필터 지우기
필터 지우기

ODE45 numel (x) = 1 error

조회 수: 2 (최근 30일)
Kurtis
Kurtis 2013년 4월 25일
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?

답변 (1개)

Zhang lu
Zhang lu 2013년 4월 25일
편집: Zhang lu 2013년 4월 25일
[TOUT,YOUT] = ODE45(ODEFUN,TSPAN,Y0) YO should be a vector to match ode function
[t,x]=ode45('Function',[0,20],[1 1])

카테고리

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