plot integral equation coming from ode solver

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.

 採用された回答

Star Strider
Star Strider 2019 年 2 月 15 日

0 投票

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 件のコメント

STP
STP 2019 年 2 月 18 日
Hi Star Strider; I did read about it. Although if I just want to use to integral function; the error still is valid.
Torsten
Torsten 2019 年 2 月 18 日
The first argument to "integral" is a function handle, not a vector of values as in your case. So either use "trapz" or "cumtrapz" as suggested or include the integration in the call to ODE15S by defining a second equation dV2/dt = V1-1 besides dV1/dt =dV1dt.
Star Strider
Star Strider 2019 年 2 月 18 日
@Torsten — Thank you.
STP
STP 2019 年 2 月 21 日
編集済み: STP 2019 年 2 月 21 日
@torsten : I tried including integration in ode solver but still I didnt get it
dV1dt = @(t,V) ((U_in1*omega*beta)/Qo) - omega_half*V;
[t1 V1] = ode15s(dV1dt, t1, y1)
dV2dt = integral(V1-1);
Amirah Algethami
Amirah Algethami 2023 年 8 月 19 日
@Torsten How to extract the integration value is it :v2(:) or v2(end)???
This is your sugesstion :"include the integration in the call to ODE15S by defining a second equation dV2/dt = V1-1 besides dV1/dt =dV1dt"
Torsten
Torsten 2023 年 8 月 19 日
V2(i) = integral_{t=tspan(1)}^{t=tspan(i)} (V1(t)-1) dt (1 <= i <= end)
Amirah Algethami
Amirah Algethami 2023 年 8 月 20 日
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 2023 年 8 月 20 日
編集済み: Torsten 2023 年 8 月 20 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

STP
2019 年 2 月 15 日

編集済み:

2023 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by