0

我有一个多项式y = 0.230 + -0.046*x + -0.208*x^2。我想计算在(X,Y)处切割另一条线的这条线的垂直线。

4

2 回答 2

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也是一个好主意,可以看到你真的有正交曲线。

于 2013-08-29T15:30:16.910 回答
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')
于 2013-08-29T14:54:25.133 回答