Error when using ode45 command,"returns a vector of length 11, but the length of initial conditions vector is 1."
조회 수: 4 (최근 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!