Finding intersection point between two functions

2 Ansichten (letzte 30 Tage)
Jose Grimaldo
Jose Grimaldo am 14 Apr. 2020
Beantwortet: Star Strider am 14 Apr. 2020
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)]);

Antworten (1)

Star Strider
Star Strider am 14 Apr. 2020
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
.

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by