Find intersection of curve and line.

2 Ansichten (letzte 30 Tage)
A Akhilesh
A Akhilesh am 1 Apr. 2021
Kommentiert: Star Strider am 5 Apr. 2021
i have two equations yw and y1 i need to find intersection of both line and curve and then find the distance of the point from origin. i have only points of y and x for making the curve and have used polynomial interpolation for that
clear
syms x1
x=[0;1;2;3];
y=[7;5;11;28];
for i=1:4
for j=1:4
a(i,j)=power(x(i),(j-1));
end
end
b=inv(a)*(y);
yw=tan(deg2rad(10))*x1+20;
y1=b(1,1)+(b(2,1)*x1)+(b(3,1)*x1.^2)+(b(4,1)*x1.^3);
fplot(yw,[0,5])
hold onclc
fplot(y1,[0,5])

Akzeptierte Antwort

Star Strider
Star Strider am 1 Apr. 2021
Try this:
syms x1
x=[0;1;2;3];
y=[7;5;11;28];
for i=1:4
for j=1:4
a(i,j)=power(x(i),(j-1));
end
end
b=inv(a)*(y);
yw=tan(deg2rad(10))*x1+20;
y1=b(1,1)+(b(2,1)*x1)+(b(3,1)*x1.^2)+(b(4,1)*x1.^3);
xv = vpasolve(y1-yw==0,x1) % X-Value At Intersection
yv = subs(yw, x1, xv) % Y-Value At Intersection
figure
fplot(yw,[0,5])
hold on
fplot(y1,[0,5])
plot(double(xv), double(yv), '+r')
hold off
xlim([0 5])
legend('yw','y1','Intersection', 'Location','best')
.
  2 Kommentare
A Akhilesh
A Akhilesh am 5 Apr. 2021
Hey!, thanks for the answer. i would like to know if the same thing would work when i have n points defining my curve, which gives me an nth degree polynomial.
Star Strider
Star Strider am 5 Apr. 2021
As always, my pleasure!
Calculating the intersections of lines defined by data (rather than expressions) from two different data sets is similar in concept, although the code differs. See Plot a point of intersection between 2 lines or curves for a typical approach.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Polynomials 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