error in ode45 - must return column vector

3 ビュー (過去 30 日間)
Chase
Chase 2014 年 10 月 4 日
コメント済み: Star Strider 2014 年 10 月 4 日
This is to simulate the response of a single degree of freedom system.
script
function [ xdot ] = sdof( t, x)
xdot = zeros(2,3);
xdot(1) = x(2);
xdot(2) = -2/3*x(1)-(1/3)*x(2);
end
command window
>> t0 = 0; tf = 20; %-- start and end time
>> x0 = [0 0.25]; %-- initial conditions
>> [t,x] = ode45('sdof',[t0 tf],x0); %-- call ODE45 solver
Error using odearguments (line 90)
SDOF must return a column vector.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
>> plot(t,x);
Undefined function or variable 't'.

回答 (1 件)

Star Strider
Star Strider 2014 年 10 月 4 日
編集済み: Star Strider 2014 年 10 月 4 日
Replace the preallocation line with:
xdot = zeros(2,1);
and you’re good to go.
Note: in R2014a, I needed to change the ode45 call to:
[t,x] = ode45(@sdof,[t0 tf],x0); %-- call ODE45 solver
Then it worked perfectly.
  2 件のコメント
Chase
Chase 2014 年 10 月 4 日
Perfect thanks so much!!!
Star Strider
Star Strider 2014 年 10 月 4 日
My pleasure!
The most sincere expression of gratitude here on MATLAB Answers is to Accept the Answer that most closely solves your problem.

サインインしてコメントする。

カテゴリ

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