plot integral equation coming from ode solver

1 view (last 30 days)
I have an equation that comes from ode solver :
[t1 V1] = ode15s(dV1dt, t1, y1); plot(t1, V1 ,'-b','lineWidth',2)
then I do some basic addition or subtraction on it for eg :
Aout1=(V1-1); plot(t1,Aout1,'-b','lineWidth',2);
Now I wish to integrate the output : So I tried with
final = integral (Aout1, 0, 4.2)
But I get error :
Error using integral (line 82) First input argument must be a function handle.
I tried other things as well; but I don't achieve what I wish. Although 'cumsum' works well on it just like that.

Accepted Answer

Star Strider
Star Strider on 15 Feb 2019
Use the trapz (link) function:
idx = find(t1 <= 0.42);
final = trapz(t1(idx), Aout1(idx))
Since you menitoned cumsum, also see the documentation for cumtrapz (link).
  8 Comments
Amirah Algethami
Amirah Algethami on 20 Aug 2023
thanks @Torsten this extract with defining dV2/dt = V1-1 , I thought ode15 will be integrated it without using integral function? please clarify it for me.
Thanks
Torsten
Torsten on 20 Aug 2023
Edited: Torsten on 20 Aug 2023
If you call ode15s with the additional ODE dV2/dt = V1(t)-1, V2(tspan(1)) = 0, ode15s will return
V2(i) = integral_{t=tspan(1)}^{t=tspan(i)} (V1(t)-1) dt (1 <= i <= end)
in the solution column for V2 in Y. The call somehow looks like
[T,Y] = ode15s(dVdt,tspan,[V1,0])
If you have further questions, please include executable code and mark the line where you have difficulties.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!