How do I integrate the output of an ode23 solver?

2 views (last 30 days)
In my specific problem I have solved an ODE with ode23 resulting in two 11x1 double vectors (E and r). The dr's resulitng are equal in size, in this case. The integrate function does work on these variable types, or can it? Creating a simple "for" loop multiplying E(i)*dr and summing is too course (11 points) and gives the wrong answer, which I know exactly. The plotted output of ode23 shows a solid line between the 11 points. So, some kind of extrapolation or estimated function must exist, or? That then could be integrated with the function integrate, or?

Answers (2)

Torsten
Torsten on 25 Sep 2018
Solve the additional ODE
dI/dt = E(t)*dr/dt
then
I(T) = integral_{t=0}^{t=T} E(t) dr
Best wishes
Torsten.

Marc Jeroense
Marc Jeroense on 25 Sep 2018
I am afraid I do not quite understand you. I added my short trial file. Hope you can have a look? I now used the trapz function. I expected the result to be more accurate.
  1 Comment
Torsten
Torsten on 26 Sep 2018
If a quantity e is the result of a solution of an ODE
de/dt = ...
and in addition to e, you want to have the integral of e over time (name it E), you can add the differential equation
dE/dt = e, E(0)=0
to your system of ODEs.
Then
E(T) = integral_{t=0}^{t=T} e(t) dt
Best wishes
Torsten.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!