Error using ODE45. Need Help Debugging

조회 수: 4 (최근 30일)
Stephen
Stephen 2014년 9월 6일
댓글: Star Strider 2014년 9월 6일
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
Stephen
Stephen 2014년 9월 6일
Thank you very much
Star Strider
Star Strider 2014년 9월 6일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (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