Error when using ode45 command,"returns a vector of length 11, but the length of initial conditions vector is 1."
5 ビュー (過去 30 日間)
古いコメントを表示
function dw_dt = equation_(t,w)
a = 1;
b = 1.35;
v= [.6:.01:.70].';
dw_dt = a*w.^(v)-b*w;
%actual script
time_period = [0 20];% time period between 0 and 20 weeks
w0 = 0.5;% intial weight of the fish
[t,w] = ode45('equation_',time_period,w0);
I'm trying to run my function using ode45. I should be able to run the function for every value of yv but for some reason i can't. when ever i try to run the function for once value of V is works perfectly fine but when i try to run it for every value of v it does not work well.
0 件のコメント
採用された回答
John Chilleri
2017 年 2 月 7 日
編集済み: John Chilleri
2017 年 2 月 7 日
Hello,
The way the ode45 command works (as I'm sure you know) is that given a state vector, in your case w, you provide a function that evaluates the derivative of w and returns dw.
A common example is with position and velocity:
state_vec = [position; velocity];
where as your 'equation_' would return:
dstate_vec = [velocity; acceleration];
it seems like you understand this; however, you are giving it an initial condition of .5, so:
w = .5;
then you are returning a dw that is a vector (because v is a vector and is apart of the computation).
So ode45 is trying to update a constant .5 with a vector dw, this is where you are encountering your error. You can fix this by either changing your dw to a scalar result, or making your initial condition an equally long vector corresponding to the length of the returned dw.
Hope this helps!
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!