how to integral by series

2 次查看(过去 30 天)
JICHAO ZHANG
JICHAO ZHANG 2023-6-20
I would like to do a cycle for t.
for example, function as t*exp(xyz),
then for t=1:5; there are vector
1*exp(xyz),2*exp(xyz),3*exp(xyz),4*exp(xyz),5*exp(xyz),
next step make sum, 1*exp(xyz)+2*exp(xyz)+3*exp(xyz)+4*exp(xyz)+5*exp(xyz),
finally, do integral by x,y,z varibles
f=0;
for t=1:5
f=f+@(x,y,z) t.*exp(xyz)
end
ff=integral3(@(x,y,z)f,0,1,0,1,0,1)
this is wrong code,but i don't know how to code right one

回答(1 个)

Dyuman Joshi
Dyuman Joshi 2023-6-20
You can not add function handles together. Instead, you can add the integrals.
format long
f=0;
for t=1:5
%I am assuming you want to do multiplication by using the notation xyz
fun = @(x,y,z) t.*exp(x.*y.*z);
%Adding integral values
f = f + integral3(fun,0,1,0,1,0,1);
end
f
f =
17.197486087940671
  3 个评论
Torsten
Torsten 2023-6-20
Or simply:
f = @(x,y,z) sum((1:5)*exp(x*y*z));
ff = integral3(@(X,Y,Z)arrayfun(@(x,y,z)f(x,y,z),X,Y,Z),0,1,0,1,0,1)
ff = 17.1975
JICHAO ZHANG
JICHAO ZHANG 2023-6-21
I see, great. using vector for t

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by