【问题标题】:Plotting Hyperbola in Matlab在 Matlab 中绘制双曲线
【发布时间】:2019-10-03 04:20:40
【问题描述】:

我试图在 Matlab 中绘制一条双曲线来模拟环绕地球的双曲线轨迹。

由于双曲方程由一个 +/- 部分(从平方根)组成,我似乎无法弄清楚如何让 Matlab 绘制它。

这是我目前的代码:

%Plotting Hyperbolic Orbit

 e = 1.05;          %Eccentricity 
 a = -147562.72;    %km
 b = abs(a)*sqrt(e.^2 -1);      %Equation for Semi-Minor Axis, b

 x1 = linspace(0.00001, a);         %From 0 to a, Upper
 x2 = linspace(-a, -0.00001);       %From -a to 0, Lower

 y1 =  sqrt((b.^2)*((x1.^2)/(a.^2)-1));  %Upper Hyperbola Part
 y2 = -sqrt((b.^2)*((x2.^2)/(a.^2)-1));  %Lower Hyperbola Part


 figure
 plot(x1, y1, x2, y2, 'b')
 grid on

我最初尝试使用从 -a 到 a 的一个 x 坐标,但由于其中包含 0,它给了我一个虚数错误,最终无法绘制它。

感谢您的帮助。

【问题讨论】:

    标签: matlab plot orbital-mechanics


    【解决方案1】:

    对于双曲线,小于 a(绝对值)的 x 值是复数。

    考虑表达式:x1.^2/a^2-1。如果x1 小于a,它们的比值将小于一,平方会使其更小,因此整个表达式将为负数。然后 y 值由负数的平方根定义。所以,绘图边界与它们应该是相反的(虽然,我想它们是完美的椭圆)。

    所以这段代码应该更接近你的预期:

     e = 1.05;          %Eccentricity 
     a = -147562.72;    %km
     b = abs(a)*sqrt(e.^2 -1);      %Equation for Semi-Minor Axis, b
    
     x1 = linspace(   a, 2*a, 1E3);         %From 0 to a, Upper
    
     ytop =  b*sqrt(x1.^2/a^2-1);  %Upper Hyperbola Part
     ybot = -b*sqrt(x1.^2/a^2-1);  %Lower Hyperbola Part
    
     figure
     plot(x1, ytop, x1, ybot, -x1, ytop, -x1, ybot);
     grid on
    

    【讨论】:

    • 非常感谢,这对您有很大帮助。我明白你在说什么,我现在明白了。再次感谢
    猜你喜欢
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    相关资源
    最近更新 更多