about useing ode23 solving ordinary differential equations
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hi all,
I have a question about using ode23 or other ode functions in Matlab to solve ordinary differential equation . The call format of ode functions is like [T,Y] = ode23(odefun,tspan,y0). odefun is the differential equations. If I set a break point in the odefun function, I can see the variable and parameter values in the odefun will update every time I press F5 .
My question is can the odefun get the last step variable or parameter values in the current step?
Thanks
댓글 수: 0
답변 (1개)
Walter Roberson
2015년 7월 11일
편집: Walter Roberson
2015년 7월 12일
No. If you need to pass values between iterations, add the values to your "y" vector. For example,
prevtime = 0; %getting the right initial conditions is important
prevs14 = 0;
initvals = [y0(:); prevtime; prevs14];
[T,OUTVALS] = ode23s(@odefun,tspan,initvals)
Y = OUTVALS(1:end-2,:); %discard the values carried between generations
with
function outvals = odefun(t, invals)
y = invals(1:end-2); %pull apart the inputs
prevtime = invals(end-1);
prevs14 = invals(end);
s14 = (sum(sin(y).^2) - prevs14)./(t-prevtime); %some intermediate calculation
newy = y * s14; %building outputs
outvals = [newy; t; s14]; %include the information to be passed between iterations
end
Remember, if you want to know what the "previous" values were, then you have the problem of what value to use for the first iteration.
Also remember to take the extra values into account when you are building the jacobian.
댓글 수: 4
craftsman
2015년 7월 11일
Walter Roberson
2015년 7월 12일
You are correct, I had a couple of typos in invoking the ode23s; I edited the invocation the way you pointed out.
Walter Roberson
2015년 7월 12일
My solution does not appear to work. I will need to investigate further.
craftsman
2015년 7월 12일
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!