Error using ODE45. Need Help Debugging

1 view (last 30 days)
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, ...

Accepted Answer

Star Strider
Star Strider on 6 Sep 2014
Edited: Star Strider on 6 Sep 2014
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 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!