Error with calling out ODE Function for my Code
显示 更早的评论
Hi All,
I'm trying to get my code to run. It's supposed to call out my odefun1 function and use it for the ODE113 solver. But I'm getting an error stating:
Undefined function 'X_0' for input arguments of type 'double'.
Error in odefun1 (line 3) x_1 = X_0(1);
Error in odearguments (line 88) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode113 (line 114) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in HW4 (line 11) [t,y] = ode113(@odefun1, tspan, X_0); %calls ODE113
My function file is saved as odefun1.m with the following code: function ydot = odefun1(t,y)
x_1 = X_0(1);
y_1 = X_0(2);
z_1 = X_0(3);
x_2 = X_0(4);
y_2 = X_0(5);
z_2 = X_0(6);
mu = 0.012; %mass ratio for Earth-Moon System
r_1 = sqrt((x_1+mu)^2 + y_1^2 + z_1^2);
r_2 = sqrt((x_1-1+mu)^2 + y_1^2 + z_1^2);
ydot(1,1) = x_2;
ydot(2,1) = y_2;
ydot(3,1) = z_2;
ydot(4,1) = x_1-((1-mu)*(x_1+mu)/r_1^3)-(mu*(x_1-1+mu)/r_2^3)+(2*y_2);
ydot(5,1) = y_1-((1-mu)*y_1/r_1^3)-(mu*y_1/r_2^3)-(2*x_2);
ydot(6,1) = -((1-mu)*z_1/r_1^3)-(mu*z_1/r_2^3);
I tried calling it from another mfile using:
t_0 = 0;
t_f = 5.906784808167686;
tspan = [t_0 t_f]; %time span to integrate over
X_0 = [0.999970555399038; -0.000035183036743; 0; 0.339376400085973; -0.243910167049855; 0]; %initial condition
[t,y] = ode113(@odefun1, tspan, X_0); %calls ODE113
but errors keep popping up. I'm not sure what's wrong. Any help is appreciated!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!