Intersection of two curves

조회 수: 76 (최근 30일)
Chinmayraj Doddarajappa
Chinmayraj Doddarajappa 2022년 8월 14일
댓글: Chinmayraj Doddarajappa 2022년 8월 14일
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')
  댓글 수: 1
Chinmayraj Doddarajappa
Chinmayraj Doddarajappa 2022년 8월 14일
Thank you so much.
It really helped me in the calculation.

댓글을 달려면 로그인하십시오.

추가 답변 (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
Chinmayraj Doddarajappa 2022년 8월 14일
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
Chinmayraj Doddarajappa 2022년 8월 14일
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