2013-08-29 31 views
-1

我有一個多項式y = 0.230 + -0.046*x + -0.208*x^2。 我想計算與此線垂直切割另一條線(X,Y)。如何計算方程到垂直於多項式的線

+0

可能重複[如何計算線段的法向量?](http://stackoverflow.com/questions/1243614/how-do-i-calculate-the-normal-vector-of-a - 線段) – Schorsch

+1

或可能的副本[如何在Matlab中找到法向量在曲線上的點](http://stackoverflow.com/questions/17324936/how-to-find-the-normal- vector-at-a-point-on-a-curve-in-matlab) – Schorsch

+0

@Schorsch這是一個基本的數學問題,但這些鏈接不提供完整的解決方案,只有它的一半... –

回答

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') 
+1

您的衍生產品需求修復:'dx = x(2)-x(1); py = -dx./dy;' –

+1

@TryHard謝謝,我糾正了它。現在'dy'是使用'diff(y)./ diff(x)'找到的。 – Dan

+0

嗨丹和努力謝謝你的幫助。還有更多的問題要完成這篇文章,你的例子xy是用<1x101 double >水平[鏈接](http://pro.ellip6.com/SebastienForum/Tab1.jpg)和我的垂直[鏈接](http://pro.ellip6.com/SebastienForum/Tab2.jpg)我怎麼能轉換從我的到你的或修改你的代碼。謝謝 – user2724407

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也是在這個例子中是一個好主意,看看你真的有正交曲線。

+0

謝謝你如果我的方程用x。^ 3和x。^ 4表示更高的順序,我該如何修改你的代碼,使用seconde命令可以正常工作。 – user2724407

+1

@ user2724407您需要計算多項式的* analytical *導數(斜率),並通過引入變量'slope'來替換我編輯的位置。 –

+0

謝謝你做到了。找到這個公式後,我想找到與另一個從double數組繪製的曲線的交點。 – user2724407