Error when using ode45 command,"returns a vector of length 11, but the length of initial conditions vector is 1."
4 views (last 30 days)
Show older comments
Stephanie Velasco
on 6 Feb 2017
Edited: Walter Roberson
on 7 Feb 2017
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 Comments
Accepted Answer
John Chilleri
on 7 Feb 2017
Edited: John Chilleri
on 7 Feb 2017
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 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!