What is the most elegant way to get yp from solution of ODE15i?

조회 수: 3 (최근 30일)
Tom Clark
Tom Clark 2015년 5월 13일
댓글: Tom Clark 2015년 5월 13일
Hi,
I'm solving an ODE using ODE15i. As per the usual use case of 15i, the function I'm integrating is a function of t,y,and prime (the time derivative of y):
function sol = myFunc
% Set up ICs and shared variables
sol = ode15i(@nested_integrand,tspan,y0,yp0)
function f = nested_integrand(t,y,yp)
% some code
end
end
However, the solution sol only contains values of t and y at the integration points. Not yp! This seems like an oversight to me, since the consistent values of yp have already been calculated within ode15i.
So my question is in two parts:
1. What is the most elegant way of getting the yp values that correspond with sol.t and sol.y?
2. Does anyone else have a use for this output? If so I'll make a feature request.
Thanks all,
Tom

채택된 답변

Torsten
Torsten 2015년 5월 13일
[Y,YP] = deval(sol,tspan)
will give you the time-derivatives of your solution variables at times tspan in the matrix YP if your call to ode15i was
sol = ode15i(@nested_integrand,tspan,y0,yp0)
Best wishes
Torsten.
  댓글 수: 1
Tom Clark
Tom Clark 2015년 5월 13일
Perfect, thanks Torsten. I'd studied the documentation of deval() but my eyes must be swimming, as I'd missed that!
What a hero :)
Tom

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Torsten
Torsten 2015년 5월 13일
If you solve for n unknowns y1,...,yn,
add n additional algebraic equations as
y(n+1)-dy(1)=0,y(n+2)-dy(2)=0,...,y(2*n)-dy(n)=0.
y(n+1),...,y(2*n) will then give you the derivatives of the variables you solved for.
Best wishes
Torsten.
  댓글 수: 2
Tom Clark
Tom Clark 2015년 5월 13일
Thanks Torsten, nice implementation. Would this affect the performance of the solver though?
Torsten
Torsten 2015년 5월 13일
Maybe if n is large ...
But I think it's less time-consuming than to solve f(t,y,yp)=0 (with fsolve,e.g.) for each output time.
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by