ode45 must return a column vector?
古いコメントを表示
I keep getting the error:
??? Error using ==> odearguments at 113
CONTROLPAPERQ must return a column vector.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
odeArgs, odeFcn, ...
Error in ==> controlPaper at 27
Q1=ode45('controlPaperQ',tB,0.0);
with the code:
%%Start by setting up all of the variables
t=0:.005:.5;
tB=fliplr(t);
save t
save tB
A=10;
B=1;
M1=ones(size(t));
for i=1:50
M1(i)=0;
end
save M1
M1b=fliplr(M1);
save M1b
%%Now to find Q
Q1=ode45('controlPaperQ',tB,0.0);
save Q1
function Qdot=controlPaperQ(t, history)
load M1
load M1b
Qdot=zeros(1,1);
Qdot=1-20.*history.*M1b-history.^2;
Any ideas?
回答 (2 件)
Walter Roberson
2012 年 6 月 29 日
consider
t=0:.005:.5; %creates a row vector
M1=ones(size(t)); %so also creates a row vector
M1b=fliplr(M1); %continues to be a row vector
And then when we look at
Qdot=1-20.*history.*M1b-history.^2;
if "history" is not a scalar or a row vector, then 20.*history.*M1b would have a dimension error, so we deduce that "history" is a scalar or row vector. And from that we deduce that Qdot is going to be a row vector also.
Unfortunately for you, the function you pass as the first argument to ode45 must return a column vector.
When you are looking over your code trying to figure out what went wrong, please try to figure out why you are ignoring time in your calculation. The "t" you initialize in your code is not the same as the "t" that will be seen inside controlPaperQ : the "t" inside that routine will be the current time of integration.
Star Strider
2012 年 6 月 29 日
I don't understand what 'history' is or what its dimensions are. I suggest you set a breakpoint at the second 'Qdot = ...' in 'controlPaperQ' to check its dimensions. If it's a row vector it would be easy enough to transpose it to make 'ode45' happy. If it's a matrix, you'll have to decide the appropriate way to fix it.
The documentation for 'ode45' states:
‘For a scalar T and a vector Y, ODEFUN(T,Y) must return a column vector
corresponding to f(t,y).’
so apparently it's just designed that way.
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!