How to find second intersection point?

Okay, so
My task is to find the intersections points of functions f1 = 1/x and f2 = sqrt(5./2 - (x^2))
I've found one of the intersections points using:
Intersections=find(abs(f1-f2)<=(0.05));
xvalues=x1(Intersections);
But looking at the graphs I see there are two intersections points, so how do I find the other?

回答 (2 件)

Star Strider
Star Strider 2022 年 9 月 17 日

0 投票

It is easiest to do this symbolically —
syms x
f1 = 1/x;
f2 = sqrt(5./2 - (x^2));
Intx = solve(f1 == f2)
Intx = 
Intxd = double(Intx)
Intxd = 2×1
1.4142 0.7071
.

6 件のコメント

Amanda
Amanda 2022 年 9 月 17 日
Is there a way to solve this without using syms? We're not allowed to use it.
Star Strider
Star Strider 2022 年 9 月 17 日
編集済み: Star Strider 2022 年 9 月 17 日
Yes, although this is slightly complicated by the fact that ‘f2’ is complex —
x = linspace(0, 5);
f1 = 1./x;
f2 = sqrt(5/2 - (x.^2));
figure
plot(x, real(f1), x, real(f2))
grid
idx = find(diff(sign(real(f1)-real(f2))));
for k = 1:numel(idx)
idxrng = max(1,idx(k)-1 : min(numel(x),idx(k)+1));
Intx(k) = interp1(real(f1(idxrng))-real(f2(idxrng)),x(idxrng),0);
end
Intx
Intx = 1×2
0.7071 1.4142
EDIT — (17 Sep 2022 at 14:18)
Using fzero
f1fcn = @(x) 1./x;
f2fcn = @(x) sqrt(5/2 - (x.^2));
for k = 1:2
Intx(k) = fzero(@(x)real(f1fcn(x))-real(f2fcn(x)), k);
end
Intx
Intx = 1×2
0.7071 1.4142
.
Amanda
Amanda 2022 年 9 月 17 日
Thank you very much! Could you explain your foor-loop (not the one in the edit)?
Star Strider
Star Strider 2022 年 9 月 17 日
My pleasure!
Sure! The fzero function is a root-finding algorithm, and can only return one root at a time, so to find more roots, it is necessary to iterate calls to it with different initial estimates. It will return the closest root to each estimate. Here, one root is closer to 1 and the second root is closer to 2, so I just used the loop counters for the initial estimates here. Usually, more elaborate initial estimates are required. I generally prefer the interp1 approach if it is applicable and if I know the region-of-interest, since it is easier to discover multiple roots or intersections with it, using the ‘idx’ approach to finding them.
Amanda
Amanda 2022 年 9 月 17 日
I tried using your code, and got the same values of x. However, looking at the graph, the second x-value is incorrect. We get x = 1.4142, while it seems to be more 1.387
Star Strider
Star Strider 2022 年 9 月 17 日
The symbolic approach solves for and , agreeing with the numeric approach, so I do not see how any other values could be correct.

サインインしてコメントする。

Torsten
Torsten 2022 年 9 月 17 日

0 投票

x1 = 0:0.0001:1.5;
f1 = 1./x1;
f2 = sqrt(5./2 - (x1.^2));
Intersections = find(abs(f1-f2)<0.00005);
xvalues=x1(Intersections)
xvalues = 1×2
0.7071 1.4142

カテゴリ

質問済み:

2022 年 9 月 17 日

コメント済み:

2022 年 9 月 17 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by