Find intersection of curve and line.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
A Akhilesh
el 1 de Abr. de 2021
Comentada: Star Strider
el 5 de Abr. de 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])
0 comentarios
Respuesta aceptada
Star Strider
el 1 de Abr. de 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 comentarios
Star Strider
el 5 de Abr. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Polynomials en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!