Find intersection of curve and line.

2 次查看(过去 30 天)
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])

采纳的回答

Star Strider
Star Strider 2021-4-1
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 个评论
A Akhilesh
A Akhilesh 2021-4-5
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 2021-4-5
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polynomials 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by