我有一个多项式y = 0.230 + -0.046*x + -0.208*x^2
。
我想计算这条线的垂线,在(X,Y)处切割另一条线。
答案 0 :(得分:1)
另一种方法是计算分析结果并不是非常困难。 (你可以使用符号工具箱,但坐在你头上的NN会这样做):
%Example data
x=0:0.1:10;
y = 0.230 + -0.046*x + -0.208*x.^2 ;
plot(x,y);
%Find the tangent and normals at all points (*edited*)
slope = (-0.046 + -2*0.208*x);
py = -1./slope; % <-- modified from Dan's expression
% to use analytical derivative
%Choose a point
n = 60;
X = x(n);
Y = y(n);
hold on
plot(X, Y, 'or')
% Copying @Dan: Find the equation of the straight line normal to that point. You can do this in one step (yn = py(n)*(x - X) + Y) but I've done it in two to illustrate where this comes from
c = Y - py(n)*X;
yn = py(n)*x + c;
plot(x, yn, 'g')
axis tight equal
在此示例中使用axis equal
也是一个好主意,可以看到您确实有正交曲线。
答案 1 :(得分:0)
%Example data
x=0:0.1:10;
y = 0.230 + -0.046*x + -0.208*x.^2 ;
plot(x,y);
%Find the tangent and normals at all points
dy = [0 diff(y)./diff(x)];
py = -1./dy;
%Choose a point
n = 60;
X = x(n);
Y = y(n);
hold on
plot(X, Y, 'or')
%Find the equation of the straight line normal to that point. You can do this in one step (yn = py(n)*(x - X) + Y) but I've done it in two to illustrate where this comes from
c = Y - py(n)*X;
yn = py(n)*x + c;
plot(x, yn, 'g')