Error using ODE45. Need Help Debugging

1 次查看(过去 30 天)
my m-file looks like
function xp=F(t,x)
xp=zeros(5,1);
m=1;
w=1;
h=.5;
y=.01;
xp(1)=-m*(w^2)*(x(2)^3)*(-(h*y)/(2*w*m))*24*x(3);
xp(2)=x(1);
xp(3)=2*w*x(4);
xp(4)=-x(2)*w*(1+((12*x(2)*x(2))/(m*w*w)))*x(3)+w*x(5);
xp(5)=-x(2)*w(1+((12*x(2)*x(2))/(m*w*w)))*x(4);
and when i set m,w,y,and h then run the code
[t,x]=ode45('F',[0,10],[0,1,.5*((1+((12*x(2)*x(2))/(m*w*w)))^(-.5)),0,.5*((1+((12*x(2)*x(2))
/(m*w*w)))^(.5))]);
i get the errors
??? Index exceeds matrix dimensions.
Error in ==> F at 11
xp(5)=-x(2)*w(1+((12*x(2)*x(2))/(m*w*w)))*x(4);
Error in ==> odearguments at 98
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 172
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

采纳的回答

Star Strider
Star Strider 2014-9-6
编辑:Star Strider 2014-9-6
I can’t run your code because at the [t,x] = ode45(... line, I get:
Undefined function or variable "x".
that probably relates to referring to it in your initial conditions.
Otherwise, you likely need to ‘vectorize’ your code, using the dot operator, replacing * with .*, / with ./, and ^ with .^.
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by