Effacer les filtres
Effacer les filtres

Intersection of two curves

26 vues (au cours des 30 derniers jours)
Chinmayraj Doddarajappa
Chinmayraj Doddarajappa le 14 Août 2022
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 commentaire
Star Strider
Star Strider le 14 Août 2022
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.

Connectez-vous pour commenter.

Réponse acceptée

Bruno Luong
Bruno Luong le 14 Août 2022
Modifié(e) : Torsten le 14 Août 2022
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 commentaire
Chinmayraj Doddarajappa
Chinmayraj Doddarajappa le 14 Août 2022
Thank you so much.
It really helped me in the calculation.

Connectez-vous pour commenter.

Plus de réponses (2)

Torsten
Torsten le 14 Août 2022
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 commentaires
Chinmayraj Doddarajappa
Chinmayraj Doddarajappa le 14 Août 2022
I have used yyaxis funtion to plot the two curves.
figure
yyaxis left
plot(N,Pi_I)
yyaxis right
plot(N,f)
Torsten
Torsten le 14 Août 2022
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.

Connectez-vous pour commenter.


dpb
dpb le 14 Août 2022
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 commentaire
Chinmayraj Doddarajappa
Chinmayraj Doddarajappa le 14 Août 2022
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by