to find co-cordinate of Intersection point of line?
1 次查看(过去 30 天)
显示 更早的评论
x=[7.8 8.25 8.5];
y=[0.96 0.99 0.94];
p=polyfit(x,y,2);
f=polyval(p,x);
plot(x,y,'o',x,f,'-');
hold on;
line([7.8 8.5],[0.96 0.94]);
hold on;
line([8.25 8.25],[0 0.99]);
Now want to compute intersection point of both lines?
0 个评论
回答(1 个)
Walter Roberson
2013-4-4
p1 = polyfit(x(1:2), y(1:2), 2);
b1 = polyval(p1, 0);
m1 = polyval(p1, 1) - b1;
p2 = polyfit(x(2:3), y(2:3), 2);
b2 = polyval(p2, 0);
m2 = polyval(p1, 1) - b2;
And now you have m1*x + b1 = m2*x + b2, so m1 * x - m2*x = b2 - b1, so (m1 - m2) * x = b2 - b1, and so x = (b2 - b1) / (m1 - m2), after which y = m1*x + b1 to find the corresponding y.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!