Intersection of two curves

76 次查看(过去 30 天)
Hi,
I am trying to find the intersection point of two curves of different functions plotted in a same graph. Can someone help me to find the [x] value of the intersection point.
Thanks
N = [1 2 3 4 5 6]
P = [1.48982012272225e-09 1.20413388047633e-08 4.17435214011468e-08 1.03854604485768e-07 2.17722472607192e-07 4.11611145129198e-07]
f = [1254.80279734744 316.932254638916 144.685314017159 85.4215488617609 58.6806449463084 44.5833312773839]
The script is,
figure
yyaxis left
plot(N,Pi_I)
yyaxis right
plot(N,f)
  1 个评论
Star Strider
Star Strider 2022-8-14
The curves do not intersect in the region-of-interest (defined by the ‘N’ vector).
It may be possible to force an intersection by extrapolating both of them, however I would not trust that result because you have no idea what the curves do outside the known values. They might never intersect, or they could have an infinite number of intersections if one or both are oscillatory and have appropriate magnitudes.

请先登录,再进行评论。

采纳的回答

Bruno Luong
Bruno Luong 2022-8-14
编辑:Torsten 2022-8-14
Intersection of to things that are not comparable? why not? just avoid using it to conclude anything that matters.
N = [1 2 3 4 5 6]
N = 1×6
1 2 3 4 5 6
P = [1.48982012272225e-09 1.20413388047633e-08 4.17435214011468e-08 1.03854604485768e-07 2.17722472607192e-07 4.11611145129198e-07]
P = 1×6
1.0e-06 * 0.0015 0.0120 0.0417 0.1039 0.2177 0.4116
f = [1254.80279734744 316.932254638916 144.685314017159 85.4215488617609 58.6806449463084 44.5833312773839]
f = 1×6
1.0e+03 * 1.2548 0.3169 0.1447 0.0854 0.0587 0.0446
figure
yyaxis left
plot(N,P)
yyaxis right
plot(N,f)
yyaxis right
ylimr = ylim;
yyaxis left
yliml = ylim;
Ps = (P-yliml(1))./diff(yliml);
fs = (f-ylimr(1))./diff(ylimr);
ds = Ps-fs;
i=find(ds(1:end-1).*ds(2:end)<0,1);
Nx = interp1(ds(i:i+1),N(i:i+1),0);
yyaxis left
hold on
plot(Nx,interp1(N,P,Nx),'ob')
yyaxis right
hold on
plot(Nx,interp1(N,f,Nx),'xr')

更多回答(2 个)

Torsten
Torsten 2022-8-14
Do you see a point of intersection ? I don't.
N = [1 2 3 4 5 6];
P = [1.48982012272225e-09 1.20413388047633e-08 4.17435214011468e-08 1.03854604485768e-07 2.17722472607192e-07 4.11611145129198e-07];
f = [1254.80279734744 316.932254638916 144.685314017159 85.4215488617609 58.6806449463084 44.5833312773839];
plot(N,P)
hold on
plot(N,f)
  2 个评论
Chinmayraj Doddarajappa
I have used yyaxis funtion to plot the two curves.
figure
yyaxis left
plot(N,Pi_I)
yyaxis right
plot(N,f)
Torsten
Torsten 2022-8-14
Don't you see the different scales of the axes ?
The curves don't intersect (at least not within the region where data are available), as can be seen in the "real" plot above.

请先登录,再进行评论。


dpb
dpb 2022-8-14
One approach might be something like
R_PF=mean(P./f); % the average scaling between the two
fn1=@(x)interp1(N,f*R_PF,x); % interpolate the scaled values
fn2=@(x)interp1(N,P,x); % and the other
fnD=@(x)fn2(x)-fn1(x); % evaluate the difference between the two, for
x=interp1(fnD(N),N,0); % finding the zero point reverse lookup/interpolation for "X"
The above produces
>> x
x =
4.5738
>> fnD(x)
ans =
5.2940e-23
>>
  1 个评论
Chinmayraj Doddarajappa
Thanks for the response. I tried the above method, I am getting x value as 3.88. But as per the graph, it should be between 2.5 and 3.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by