フィルターのクリア

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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by