Finding intersection point between two functions

5 ビュー (過去 30 日間)
Jose Grimaldo
Jose Grimaldo 2020 年 4 月 14 日
回答済み: Star Strider 2020 年 4 月 14 日
How do can I find the intersection point between anonymous function L and L2 and plot the intersection point?
A=[0 2.5 3.8 4.5 6.7 7.2]
B=[0 0.6 1.1 1.6 2.6 3.7]
P=polyfit(A(1:3),B(1:3));
L=@(x) P(1).*x + P(2);
P2=polyfit(A(4:6),B(4:6));
L2=@(x) P2(1).*x + P2(2);
% Plotting function L from A(1) to intersection point
fplot(L,[A(1),fzero(L2-L,0)]);

回答 (1 件)

Star Strider
Star Strider 2020 年 4 月 14 日
Try this:
A=[0 2.5 3.8 4.5 6.7 7.2];
B=[0 0.6 1.1 1.6 2.6 3.7];
P=polyfit(A(1:3),B(1:3),1);
L=@(x) P(1).*x + P(2);
P2=polyfit(A(4:6),B(4:6),1);
L2=@(x) P2(1).*x + P2(2);
R1 = polyval(P,A(1:3));
R2 = polyval(P2,A(4:6));
x_int = (P2(2)-P(2))/(P(1)-P2(1)) % Algebra
y_int = polyval(P, x_int) % ‘polyval’
x_int = fzero(@(x) L(x)-L2(x), 1) % ‘fzero’
y_int = polyval(P, x_int) % ‘polyval’
figure
plot(A, B, '.-')
hold on
plot(A(1:3), R1)
plot(A(4:6), R2)
plot(x_int, y_int, 'p')
hold off
.

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by