我有一個程序運行ode15s幾千次,以找到一個特定的解決方案。但是,我越來越多的集成容忍錯誤,如下列:MATLAB:atan2破解ode15s
"Warning: Failure at t=5.144337e+02. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (1.818989e-12) at time t."
這樣的警告導致程序大幅減慢,有時甚至陷於完全停止。下面是一些測試代碼重新產生錯誤:
%Simulation constants
G = 6.672e-11; %Gravitational constant
M = 6.39e23; %Mass of Mars (kg)
g = 9.81; %Gravitational acceleration on Earth (m/s^2);
T1 = 845000/3; %Total engine thrust, 1 engine (N)
Isp = 282; %Engine specific impulse (s)
mdot1 = T1/(g*Isp); %Engine mass flow rate (kg/s)
xinit_on2 = [72368.8347685214;
3384891.40103322;
-598.36623436025;
-1440.49702235844;
16330.430678033]
tspan_on2 = [436.600093957202, 520.311296453027];
[t3,x3] = ode15s(@(t,x) engine_on_2(t, x, G, g, M, Isp, T1), tspan_on2, xinit_on2)
其中函數engine_on_2
包含微分方程該型號火箭的下降的系統,並且由下式給出,
function xdot = engine_on_2(t, x, G, g, M, Isp, T1)
gamma = atan2(x(4),x(3)); %flight-path angle
xdot = [x(3); %xdot1: x-velocity
x(4); %xdot2: y-velocity
-(G*M*x(1))/((x(1)^2+x(2)^2)^(3/2))-(T1/x(5))*cos(gamma); %xdot3: x-acceleration
-(G*M*x(2))/((x(1)^2+x(2)^2)^(3/2))-(T1/x(5))*sin(gamma); %xdot4: y-acceleration
-T1/(g*Isp)]; %xdot5: engine mass flow rate
end
有做了一些測試,似乎由於使用gamma = atan2(x(4),x(3))
中的atan2函數得到了集成容差警告,該函數用於計算火箭的飛行路徑角度。如果我將atan2更改爲另一個函數(例如cos或sin),則不再有任何集成容差警告(儘管由於此類更改,我的解決方案顯然不正確)。因此,我想知道我是否錯誤地使用了atan2,或者是否有辦法以不同的方式實現它,這樣我就不會再遇到集成容差錯誤。此外,是不是我不正確,並且它是導致錯誤的其他東西而不是atan2?
檢查發佈的解決方案,看看是否適合你。 – Matt