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 Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by