Errors using ode45
显示 更早的评论
I'm getting the following errors when trying to use ode45, and I'm not sure how to fix them.
function:
function xdot = eom(t, x, Ix, Iy, Iz)
%define constants
%Assume no external moments
Mx = 0;
My = 0;
Mz = 0;
xdot(1) = (Mx./Ix) - (Iz-Iy)*x(2)*x(3)/Ix;
xdot(2) = (My./Iy) - (Ix-Iz)*x(1)*x(3)/Iy;
xdot(3) = (Mz./Iz) - (Iy-Ix)*x(1)*x(2)/Iz;
xdot = xdot';
return
ode:
%Define PMOIs
Ix = 2887; %kg-m^2
Iy = 2887; %kg-m^2
Iz = 5106; %km-m^2
%Define initial conditions
x1_0 = 0.6; % OmegaX rad/s
x2_0 = 0; % OmegaY rad/s
x3_0 = 1.1; % OmegaZ rad/s
IC = [x1_0; x2_0; x3_0]; %initial conditions matrix
%define timestep
t0 = 0; %initial time
tf = 10;
interval = [t0 tf]; %timestep
%Numerically solve ODE
[t,x] = ode45('eom', interval, IC,Ix,Iy,Iz);
omegaX = x(:,1);
omegaY = x(:,2);
omegaZ = x(:,3);
Errors:
Error using /
Matrix dimensions must agree.
Error in eom (line 8)
xdot(1) = (Mx./Ix) - (Iz-Iy)*x(2)*x(3)/Ix;
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 HW11 (line 18)
[t,x] = ode45('eom', interval, IC,Ix,Iy,Iz);
I can't figure out what the errors mean or how to get rid of them. If somebody could please help me properly use ode45 to find the solution to this function that would be great!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!