ODE45 Code Issue

14 次查看(过去 30 天)
Ryan Bingaman
Ryan Bingaman 2020-3-5
Any help would be greatly appreciated on this code! The error messages are located beneath the code.
[T,X] = ode45(@(t,x) ode45for3B(t,x), [0,10], [0,0]);
function [xdot] = ode45for3B(t,x)
xdot = [0;0;0;0];
xdot(1) = x(2);
xdot(2) = (-5.667).*x(1) - (1.333333).*x(2) + (3.667).*x(3) + (1.333333).*x(4);
xdot(3) = x(4);
xdot(4) = (2.5).*x(1) + (0.9091).*x(2) - (2.5).*x(3) - (0.9091).*x(4) + (4.5454);
end
Index exceeds the number of array elements (2).
Error in ME357_HW6_3B>ode45for3B (line 15)
xdot(2) = (-5.667).*x(1) - (1.333333).*x(2) + (3.667).*x(3) + (1.333333).*x(4);
Error in ME357_HW6_3B>@(t,x)ode45for3B(t,x) (line 10)
[T,X] = ode45(@(t,x) ode45for3B(t,x), [0,10], [0,0]);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in ME357_HW6_3B (line 10)
[T,X] = ode45(@(t,x) ode45for3B(t,x), [0,10], [0,0]);

回答(1 个)

Star Strider
Star Strider 2020-3-5
Four differential equations require four initial conditions.
[T,X] = ode45(@(t,x) ode45for3B(t,x), [0,10], [0,0]);
↑ ← HERE
there are only two.
  2 个评论
Ryan Bingaman
Ryan Bingaman 2020-3-5
Can't believe it was something that simple that I missed. Thank you!!
Star Strider
Star Strider 2020-3-5
My pleasure!
If my Answer helped you solve your problem, please Accept it!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by