ODE45 numel (x) = 1 error

2 views (last 30 days)
Kurtis
Kurtis on 25 Apr 2013
I am trying to solve a second order ODE using ODE45. I created a function based on some examples I found:
function xp = Function(t,x)
xp = zeros(2,1);
xp(1) = x(2);
xp(2) = (-2*x(2))-(exp(-t)*x(1));
It seemed pretty basic to me but when I try to run the solver it give me this:
>> [t,x]=ode45('Function',[0,20],0)
Attempted to access x(2); index out of bounds because numel(x)=1.
Error in Function (line 3) xp(1) = x(2);
Error in odearguments (line 88) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 114) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
What am I doing wrong with my indexing that is holding me out from solving the equation?

Answers (1)

Zhang lu
Zhang lu on 25 Apr 2013
Edited: Zhang lu on 25 Apr 2013
[TOUT,YOUT] = ODE45(ODEFUN,TSPAN,Y0) YO should be a vector to match ode function
[t,x]=ode45('Function',[0,20],[1 1])

Tags

Community Treasure Hunt

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

Start Hunting!