문제

I have a polynomial y = 0.230 + -0.046*x + -0.208*x^2 . I want to calculate the perpendicular to this line cutting another line at (X,Y).

도움이 되었습니까?

해결책 2

%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')

다른 팁

An alternative is to compute the analytical result which is not terribly difficult. (you could use the symbolic toolbox for that but the NN sitting on your head will do):

%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

Using axis equal is also a good idea in this example to see that you really have orthogonal curves.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top