Find intersection of curve and line.

조회 수: 2 (최근 30일)
A Akhilesh
A Akhilesh 2021년 4월 1일
댓글: Star Strider 2021년 4월 5일
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