Numerical Integration of function with many parameters

Hi, I've been trying to do this code on matlab but keep getting error.
I want to integrate this function fun= @(t,Mycp,L,r)Mycp*L*exp(-r*t) with n= integral(@(t)fun(t,Mycp,L,r),0,100).
The interval t=[0 100]
The parameters are Mycp=[0 10], L=1,r=0.03,
Please help!

 採用された回答

Star Strider
Star Strider 2019 年 6 月 3 日

1 投票

Use the 'ArrayValued' (link) name-value pair:
Mycp = [0 10];
L = 1;
r = 0.03;
fun = @(t,Mycp,L,r)Mycp*L*exp(-r*t);
n = integral(@(t)fun(t,Mycp,L,r),0,100, 'ArrayValued',1)
producing:
n =
0 316.737643877379

5 件のコメント

JACINTA ONWUKA
JACINTA ONWUKA 2019 年 6 月 4 日
Thanks!
What if i want to generate diferent values of n depending on Mycp?
for Mycp=0:1:9
disp(Mycp)
L = 1;
r = 0.03;
fun = @(t,Mycp,L,r) Mycp*L*exp(-r*t);
n = integral(@(t)fun(t,Mycp,L,r),0,100, 'ArrayValued',1)
end
Torsten
Torsten 2019 年 6 月 4 日
But that's exactly what Star Strider's code does ...
You only have to set
Mycp = 0:1:9
instead of
Mycp = [0 10]
Star Strider
Star Strider 2019 年 6 月 4 日
@Torsten —
Thank you! (I was away for a few minutes.)
JACINTA ONWUKA
JACINTA ONWUKA 2019 年 6 月 4 日
Thanks!!
Star Strider
Star Strider 2019 年 6 月 4 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by