Spring 2004 Math 253/501–503 13 Multiple Integrals ss: A

advertisement
Spring 2004 Math 253/501–503
13 Multiple Integrals
ss: A numerical integration routine
c
Wed, 10/Mar
2004,
Art Belmonte
%
delete j1.txt; diary j1.txt
clear; clc; close all; echo on
%
% J1: First single integral test
%
format long
syms x
i0 = int(xˆ2, x, 2, 3) % exact result
i1 = ss(xˆ2, [x 2 3 10]) % approx result, 10 subintervals
i2 = ss(xˆ2, [x 2 3 20]) % approx result, 20 subintervals
err = abs(i1-i2)
%
Summary
The routine ss (“simple Simpson”) computes approximations to
single, double, or triple integrals using Simpson’s rule in one or
several dimensions. It allows for nonrectangular simple regions of
integration when computing multiple integrals. In this regard, it is
more general that Cooper’s simp2 and simp3 routines and simpler
to use to boot. In this regard, I recommend that you use my ss
routine in preference to his routines. Here is the online help for ss.
echo off; diary off
2. Second single integral example
Z
4
Compute
2
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
SS
−1
(sin x) etan
x
d x and estimate the error involved.
Approximation to an integral using Simpson’s rule.
ss(h,M) returns an approximation to the integral of h
using Simpson’s rule over a domain specified by M, which
is a matrix of ranges in rows from innermost to outermost.
Solution
Each row is a 4-vector [x,a,b,n] representing the range of
x as follows. Inner ranges may depend on outer variables.
Remember that tan−1 x in MATLAB is written atan.
x: a symbolic representing the variable of integration.
a: a double or symbolic which represents
the lower bound of x
b: a double or symbolic which represents
the upper bound of x
n: number of subdivisions of the span [a,b];
%
it MUST be even.
MATLAB Examples
For brevity, I’ve included only the M-file for each example that
you type into the MATLAB Editor. When you execute this script
M-file, you’ll see a diary file in the Command Window. Try these
yourselves and verify that you get the stated results. (The diary
files themselves appear at the end of this handout concatenated
together.)
echo off; diary off
3. First double integral example
Find the mass of the lamina (flat plate) in the x y-plane bounded
by the triangle with vertices (1, 1), (3, 5), (6, 1). Its density is
δ = e x+y .
1. First single integral example
Z
3
Compute
%
delete j2.txt; diary j2.txt
clear; clc; close all; echo on
%
% J2: Second single integral test
%
format long
syms x
i1 = ss(sin(x)*exp(atan(x)), [x 2 4 50])
i2 = ss(sin(x)*exp(atan(x)), [x 2 4 100])
err = abs(i1-i2)
%
x 2 d x, both exactly via int and approximately via ss.
2
Solution
Solution
Via cline2pt and solve on a TI-89 or within MATLAB, we see
that the triangular domain is
1
The exact value is 19
3 = 6 3 ; the approximate value is 6.3333.
When using ss (or any numerical integration routine), you should
compute two approximations by refining the partition, typically by
doubling the number of subintervals involved in each dimension.
The absolute value of the difference between the approximations
gives an estimate of error involved.
27 − 3y
y+1
≤x≤
,
D = (x, y) :
2
4
The mass is 5554.92 g.
1
1≤y≤5 .
5. Third double integral example
Triangular lamina
6
Compute the area of the polar region bounded by r = 2 + sin θ
and r = 2 − cos θ between θ = 34 π and θ = 74 π. Give an exact
result using int and an approximate one using ss.
5
x = (y + 1) / 2
4
x = (27 − 3y) / 4
3
90
2
3
120
60
2
1
0
150
30
1
r = 2 + sinθ
0
1
2
3
4
5
6
7
180
%
delete j3.txt; diary j3.txt
clear; clc; close all; echo on
%
% J3: First double integral test
%
format bank
syms x y
%
L1 = cline2pt([1 1], [3 5]);
x1 = solve(L1, x); pretty(x1)
L2 = cline2pt([3 5], [6 1]);
x2 = solve(L2, x); pretty(x2)
%
c = (y+1)/2; d = (27-3*y)/4;
f = exp(x+y);
exact mass = int(int(f, x,c,d), y,1,5)
eval(exact mass)
m1 = ss(f, [x c d 50; y 1 5 50])
m2 = ss(f, [x c d 100; y 1 5 100])
format long
err = abs(m1-m2)
%
r = 2 − cosθ
4 Z 6+cos x
1
300
240
270
Solution
The area
Z Z is
A=
−1 (x+y)
etan
D
Z
1 dA =
7π/4 Z 2−cos θ
3π/4
2+sin θ
√
1 · r dr dθ = 4 2 ≈ 5.66 cm2 .
%
delete j5.txt; diary j5.txt
clear; clc; close all; echo on
%
% J5: Third double integral test
%
format long
syms r t
c = 2+sin(t); d = 2-cos(t);
f = r;
a = int(int(r, r,c,d), t,3/4*pi,7/4*pi)
eval(a)
a1 = ss(f, [r c d 40; t 3/4*pi 7/4*pi 40])
a2 = ss(f, [r c d 80; t 3/4*pi 7/4*pi 80])
err = abs(a1-a2)
%
4. Second double integral example
Z
330
210
echo off; diary off
Compute approximations to
0
d y d x using
x sin x
a 30 × 30 grid, then a 60 × 60 grid, respectively. Estimate the
error involved.
echo off; diary off
6. First triple integral example
Solution
Determine the mass of the solid E that lies between the planes
z = 1 and z = 9 + x + y over the finite region D in the x y-plane
between the line y = x − 2 and the parabola 4 − x 2 . The density
of the solid (in kg/m3 ) is δ = 17 + x + y.
The result is roughly 58.54.
%
delete j4.txt; diary j4.txt
clear; clc; close all; echo on
%
% J4: Second double integral test
%
format long
syms x y
c = x*sin(x); d = 6+cos(x);
f = exp(atan(x+y));
i1 = ss(f, [y c d 30; x 1 4 30])
i2 = ss(f, [y c d 60; x 1 4 60])
err = abs(i1-i2)
%
Solution
• Solve y = x − 2 and y = 4 − x 2 simultaneously for x and y.
This yields intersection points (x, y) = (−3, −5) and
(x, y) = (2, 0). Hence the mass of the solid is given by
Z
2
Z
4−x 2
−3 x−2
echo off; diary off
2
Z
0
9+x+y
17+x+y dz d y d x =
57500
≈ 2738.10 kg.
21
MATLAB Diary Files
%
delete j6.txt; diary j6.txt
clear; clc; close all; echo on
%
% J6: First triple integral test
%
format long
syms x y z
f = 17+x+y;
m = int(int(int(f, z,1,9+x+y), y,x-2,4-xˆ2), x,-3,2)
eval(m)
m1 = ss(f, [z 1 9+x+y 30; y x-2 4-xˆ2 30; x -3 2 30])
m2 = ss(f, [z 1 9+x+y 60; y x-2 4-xˆ2 60; x -3 2 60])
err = abs(m1-m2)
%
Here is a concatenation of the seven diary files.
%
::::::::::::::
j1.txt
::::::::::::::
%
% J1: First single integral test
%
format long
syms x
i0 = int(xˆ2, x, 2, 3) % exact result
echo off; diary off
i0 =
19/3
7. Second triple integral example
i1 = ss(xˆ2, [x 2 3 10]) % approx result, 10 subintervals
i1 =
6.33333333333333
i2 = ss(xˆ2, [x 2 3 20]) % approx result, 20 subintervals
i2 =
6.33333333333333
err = abs(i1-i2)
err =
8.881784197001252e-16
%
echo off; diary off
::::::::::::::
j2.txt
::::::::::::::
%
% J2: Second single integral test
%
format long
syms x
i1 = ss(sin(x)*exp(atan(x)), [x 2 4 50])
i1 =
0.60685953462606
i2 = ss(sin(x)*exp(atan(x)), [x 2 4 100])
i2 =
0.60685949731812
err = abs(i1-i2)
err =
3.730793940448507e-08
%
echo off; diary off
::::::::::::::
j3g.txt
::::::::::::::
%
% J3g: graphics
%
M = [1 1; 3 5; 6 1]
M =
1
1
3
5
6
1
x = M(:,1); y = M(:,2);
fill(x,y,’m’); grid on; axis equal
axis([0 7 0 6])
%
echo off; diary off
::::::::::::::
j3.txt
::::::::::::::
%
% J3: First double integral test
%
format bank
syms x y
%
L1 = cline2pt([1 1], [3 5]);
x1 = solve(L1, x); pretty(x1)
What is the volume of the pumpkin bounded by the surface
ρ = (1 + φ) cos φ that sits on the x y-plane (z = 0)? Lengths are
in feet. Make sure to use the correct upper limit for φ. It is neither
π nor 2π!
Pumpkin!
1.5
1
0.5
0
1
1
0
0
−1
−1
Solution
The volume is
ZZZ
1 dV
V =
E
Z
=
=
0
2π
Z
π/2 Z (1+φ) cos φ
0
0
1ρ 2 sin φ dρ dφ dθ
3π 3
9π 2
π
π4
+
+
−
≈ 2.30 ft3 .
128
64
256
12
%
delete j7.txt; diary j7.txt
clear; clc; close all; echo on
%
% J7: Second triple integral test
%
format long
syms p r t
f = rˆ2*sin(p);
V = int(int(int(f, r,0,(1+p)*cos(p)), p,0,pi/2), t,0,2*pi);
pretty(V)
eval(V)
V1 = ss(f, [r 0 (1+p)*cos(p) 20; p 0 pi/2 20; t 0 2*pi 20])
V2 = ss(f, [r 0 (1+p)*cos(p) 40; p 0 pi/2 40; t 0 2*pi 40])
err = abs(V1-V2)
%
1/2 y + 1/2
L2 = cline2pt([3 5], [6 1]);
x2 = solve(L2, x); pretty(x2)
echo off; diary off
3
27/4 - 3/4 y
%
c = (y+1)/2; d = (27-3*y)/4;
f = exp(x+y);
exact mass = int(int(f, x,c,d), y,1,5)
eval(a)
ans =
5.65685424949238
a1 = ss(f, [r c d 40; t 3/4*pi 7/4*pi 40])
a1 =
5.65685544618062
a2 = ss(f, [r c d 80; t 3/4*pi 7/4*pi 80])
a2 =
5.65685432424420
err = abs(a1-a2)
err =
1.121936416659253e-06
%
echo off; diary off
::::::::::::::
j6.txt
::::::::::::::
%
% J6: First triple integral test
%
format long
syms x y z
f = 17+x+y;
m = int(int(int(f, z,1,9+x+y), y,x-2,4-xˆ2), x,-3,2)
exact mass =
10/3*exp(8)-4*exp(7)+2/3*exp(2)
eval(exact mass)
ans =
5554.92
m1 = ss(f, [x c d 50; y 1 5 50])
m1 =
5554.92
m2 = ss(f, [x c d 100; y 1 5 100])
m2 =
5554.92
format long
err = abs(m1-m2)
err =
0.00159950936359
%
echo off; diary off
::::::::::::::
j4.txt
::::::::::::::
%
% J4: Second double integral test
%
format long
syms x y
c = x*sin(x); d = 6+cos(x);
f = exp(atan(x+y));
i1 = ss(f, [y c d 30; x 1 4 30])
i1 =
58.53993483305155
i2 = ss(f, [y c d 60; x 1 4 60])
i2 =
58.53995019653286
err = abs(i1-i2)
err =
1.536348130315446e-05
%
echo off; diary off
::::::::::::::
j5g.txt
::::::::::::::
%
% J5g: graphics
%
t1 = 3/4*pi : pi/72 : 7/4*pi;
t2 = 7/4*pi : -pi/72 : 3/4*pi;
r1 = 2 + sin(t1); r2 = 2 - cos(t2);
x1 = r1 .* cos(t1); y1 = r1 .* sin(t1);
x2 = r2 .* cos(t2); y2 = r2 .* sin(t2);
x = [x1 x2]; y = [y1 y2];
polar(t1,r1,’b’); hold on
polar(t2,r2,’r’)
fill(x,y,’y’)
polar(t1,r1,’b’)
polar(t2,r2,’r’)
%
echo off; diary off
::::::::::::::
j5.txt
::::::::::::::
%
% J5: Third double integral test
%
format long
syms r t
c = 2+sin(t); d = 2-cos(t);
f = r;
a = int(int(r, r,c,d), t,3/4*pi,7/4*pi)
m =
57500/21
eval(m)
ans =
2.738095238095238e+03
m1 = ss(f, [z 1 9+x+y 30; y x-2 4-xˆ2 30; x -3 2 30])
m1 =
2.738095940976985e+03
m2 = ss(f, [z 1 9+x+y 60; y x-2 4-xˆ2 60; x -3 2 60])
m2 =
2.738095281227970e+03
err = abs(m1-m2)
err =
6.597490146305063e-04
%
echo off; diary off
::::::::::::::
j7.txt
::::::::::::::
%
% J7: Second triple integral test
%
format long
syms p r t
f = rˆ2*sin(p);
V = int(int(int(f, r,0,(1+p)*cos(p)), p,0,pi/2), t,0,2*pi);
pretty(V)
4
1/128 pi
3
2
- 1/12 pi
eval(V)
ans =
2.29960663501885
V1 = ss(f, [r 0 (1+p)*cos(p) 20; p 0 pi/2 20; t 0 2*pi 20])
V1 =
2.29955744452127
V2 = ss(f, [r 0 (1+p)*cos(p) 40; p 0 pi/2 40; t 0 2*pi 40])
V2 =
2.29960358477936
err = abs(V1-V2)
err =
4.614025808979960e-05
%
echo off; diary off
a =
4*2ˆ(1/2)
4
+ 3/64 pi
+ 9/256 pi
Download