display(' ')
display(' ')
display(' ')
display('Computing an iterated triple integral in several ways.')
display(' ')
display('syms x y z')
display('f=@(x,y,z)x.^2 + y.^2 + z.^2;')
display('Limits of integration are from 0 to 3 in z, from 0 to 2 in y,')
display('from 0 to 1 in x and the integration is carried out fist in x,')
display('then in y, and then in z')
display(' ')
syms x y z
display('----------------------------------------')
Computing an iterated triple integral in several ways.
syms x y z
f=@(x,y,z)x.^2 + y.^2 + z.^2;
Limits of integration are from 0 to 3 in z, from 0 to 2 in y,
from 0 to 1 in x and the integration is carried out fist in x,
then in y, and then in z
----------------------------------------
display('First using symbolic integration:')
display(' ')
display('intx=int(f,x,0,1);')
display('inty=int(intx,y,0,2);')
display('int(inty,z,0,3)')
f=@(x,y,z)x.^2 + y.^2 + z.^2;
intx=int(f,x,0,1);
inty=int(intx,y,0,2);
int(inty,z,0,3)
display('----------------------------------------')
First using symbolic integration:
intx=int(f,x,0,1);
inty=int(intx,y,0,2);
int(inty,z,0,3)
ans =
28
----------------------------------------
display('Then using triplequad command:')
display(' ')
display(' ')
display('xmax = 1;')
display('ymax = 2;')
display('zmax = 3;')
display('triplequad(@(x,y,z)x.^2+y.^2+z.^2,0,xmax,0,ymax,0,zmax);')
display(' ')
xmax = 1;
ymax = 2;
zmax = 3;
triplequad(@(x,y,z)x.^2+y.^2+z.^2,0,xmax,0,ymax,0,zmax)
display('----------------------------------------')
Then using triplequad command:
xmax = 1;
ymax = 2;
zmax = 3;
triplequad(@(x,y,z)x.^2+y.^2+z.^2,0,xmax,0,ymax,0,zmax);
ans =
28
----------------------------------------
display(' ')
display('Now using quadvec')
display(' ')
display(' ')
display('inner=@(y,z)quadvec(@(x)f(x,y,z),0,1);')
display('middle=@(z)quadvec(@(y)inner(y,z),0,2);')
display('quadvec(middle,0,3)')
display(' ')
inner=@(y,z)quadvec(@(x)f(x,y,z),0,1);
middle=@(z)quadvec(@(y)inner(y,z),0,2);
quadvec(middle,0,3)
display(' ')
display('---------------------------------------')
Now using quadvec
inner=@(y,z)quadvec(@(x)f(x,y,z),0,1);
middle=@(z)quadvec(@(y)inner(y,z),0,2);
quadvec(middle,0,3)
ans =
28
---------------------------------------
display(' ')
display('This last method can be used if inner integrals have')
display('variable limits, e.g. the integral')
display('from 0 to 1 in z, of the integral from 0 to 1-z in y,')
display('of the integral from 0 to 1-y-z of the function')
display('x^2 + y^2 +z^2 is produced by the following code.')
display(' ')
display('warning off all')
display('inner=@(y,z)quadvec(@(x)f(x,y,z),0,1-y-z);')
display('middle=@(z)quadvec(@(y)inner(y,z),0,1-z);')
display('quadvec(middle,0,1)')
display('warning on')
display(' ')
warning off all
inner=@(y,z)quadvec(@(x)f(x,y,z),0,1-y-z);
middle=@(z)quadvec(@(y)inner(y,z),0,1-z);
quadvec(middle,0,1)
warning on
display('----------------------------------------')
This last method can be used if inner integrals have
variable limits, e.g. the integral
from 0 to 1 in z, of the integral from 0 to 1-z in y,
of the integral from 0 to 1-y-z of the function
x^2 + y^2 +z^2 is produced by the following code.
warning off all
inner=@(y,z)quadvec(@(x)f(x,y,z),0,1-y-z);
middle=@(z)quadvec(@(y)inner(y,z),0,1-z);
quadvec(middle,0,1)
warning on
ans =
0.0500
----------------------------------------
display(' ')
display(' ')
display('The same can be carried out using symbolic integration.')
display(' ')
display('inner=int(f,x,0,1-y-z);')
display('middle=int(inner,y,0,1-z);')
display('double(int(middle,0,1))')
display(' ')
inner=int(f,x,0,1-y-z);
middle=int(inner,y,0,1-z);
double(int(middle,0,1))
The same can be carried out using symbolic integration.
inner=int(f,x,0,1-y-z);
middle=int(inner,y,0,1-z);
double(int(middle,0,1))
ans =
0.0500