# how to integral by series

1 view (last 30 days)
JICHAO ZHANG on 20 Jun 2023
Commented: JICHAO ZHANG on 21 Jun 2023
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
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Answers (1)

Dyuman Joshi on 20 Jun 2023
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 CommentsShow 1 older commentHide 1 older comment
Torsten on 20 Jun 2023
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 on 21 Jun 2023
I see, great. using vector for t

Sign in to comment.

### Categories

Find more on Simulink in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!