Spring 2004 Math 253/501–503 Surface Graphics c Wed, 31/Mar 2004, Art Belmonte Solution When the paraboloids intersect, their z-coordinates are equal. Summary 4 + x 2 + y2 4x 2 + 4y 2 = = 12 − 3x 2 − 3y 2 8 4r 2 r2 = = 8 2 r = hvsd My routine hvsd (“Horizontally or Vertically Simple Data”) is principally designed to create rectangular coordinate data that is used to graph surfaces. It allows for both rectangluar and nonrectangular parameter regions; e.g, regions that are rectangular, triangular, bounded by curves, etc. Type “help hvsd” in the MATLAB Command Window for exhaustive details. That said, you’ll probably find the examples in this handout much easier to understand (because they’re shorter). √ √ ± 2; pick 2. Using cylindrical coordinates, we saw in class that the volume is Z ZZZ 1 dV = V = 0 E √ Z 2 12−3r 2 Z 2π 4+r 2 0 1·r dz dr dθ = 8π ≈ 25.13 cm3 . As shown in class, here is the code that produced the plot. The hvsd routine provides a way to produce surface graphics that is both easier to use and more general than qsurf. % % Example Zero: A surface plot of intersecting % circular paraboloids with curve of intersection % r = linspace(0, sqrt(2), 10); t = linspace(0, 2*pi, 37); [R,T] = meshgrid(r,t); X = R .* cos(T); Y = R .* sin(T); Z1 = 4 + R.ˆ2; Z2 = 12 - 3.*R.ˆ2; surf(X,Y,Z1, ’FaceColor’, ’c’, ’EdgeColor’, ’k’) hold on surf(X,Y,Z2, ’FaceColor’, ’y’, ’EdgeColor’, ’k’) x = sqrt(2).*cos(t); y = sqrt(2).*sin(t); z = 0*x + 6; plot3(x,y,z, ’m’, ’LineWidth’, 4) % Like many of the routines I’ve written, hvsd can be pushed beyond its design specs to do some pretty unusual graphics. More on this later. Parametric surfaces Cooper does a good job in Section 6.4 of A MATLAB Companion for Multivariable Calculus in explaining how to graph parametric surfaces using MATLAB. I’ll give several examples from our lecture handouts that show the actual code used to produce the graphics. echo off; diary off 1. Explicit surface with a rectangular parameter region MATLAB Examples Graph z = x 2 + y 2 over the region −1 ≤ x ≤ 2, 0 ≤ y ≤ 3. 0. The “need-to-know” example for Exam 3 10 2 y z 3 10 5 5 0 3 0 3 2 2 1 1 y Find the volume of the solid bounded below by the circular paraboloid z = 4 + x 2 + y 2 and above by the circular paraboloid z = 12 − 3x 2 − 3y 2 . 4 15 z At the end of class on Tuesday, 30/Mar, we graphed intersecting circular paraboloids and found the volume between them. For your benefit, we kick the party off by replicating this example. hvsd / Example 1: Parameter region hvsd / Example 1: Solid color with black mesh hvsd / Example 1: Standard color map 15 1 0 2 2 −1 x 1 1 0 0 y 0 0 −1 x −1 −2 −1 0 1 2 3 x Solution Example 0: "When paraboloids intersect!" We could do this one the conventional way with linspace and meshgrid. However, hvsd mimicks the way you’d set up a mutiple integral (inner and outer ranges), so it helps you in that way as well. In the code below, note that the “receiving” matrices X , Y , and Z on the left-hand side of the assignment statement in which hvsd appears occur in the same order as the arguments passed to the routine. You follow up the data generation with a surface graphics command: usually surf, but others are possible (mesh, contour, pcolor, etc.). z = 12 − 3x2 − 3y2 12 z 10 8 Curve of intersection 6 4 2 0 y −2 −2 0 2 2 2 z=4+x +y x 1 By default, a standard multicolor color map (“jet”) is used. You may alternatively specify a solid color. As you saw in Example Zero, this is useful when you have separate faces that you’d like to distinguish. (These are called surface “patches.”) Here are two codes that produced the respective plots. t = linspace(1, 3, 20); x1 = t; y1 = 0*t+1; x1 = fliplr(x1); y1 = fliplr(y1); x2 = t; y2 = 5/2 - t/2; x = [x1 x2]; y = [y1 y2]; fill(x,y,’g’); grid on; axis equal; axis([0.5 3.5 0.5 2.5]) % hold on plot([0.5 3.5], [0 0], ’k’, ’LineWidth’, 2) plot([0 0], [0.5 2.5], ’k’, ’LineWidth’, 2) % %========== % % hvsd / Example 1: surface pix % syms x y [Z X Y] = hvsd(xˆ2 + yˆ2, [x -1 2 20], [y 0 3 20]); surf(X,Y,Z) figure surf(X,Y,Z, ’FaceColor’, ’m’, ’EdgeColor’, ’k’) % echo off; diary off %========== % % hvsd / Example 1: parameter region in xy-plane % M = [-1 0; 2 0; 2 3; -1 3]; x = M(:,1); y = M(:,2); fill(x,y,’g’); grid on; axis equal; axis([-2 3 -1 4]) % hold on plot([-2 3], [0 0], ’k’, ’LineWidth’, 2) plot([0 0], [-1 4], ’k’, ’LineWidth’, 2) set(gca, ’Ytick’, -1:4) % echo off; diary off echo off; diary off 3. Explicit surface with a curved parameter region Graph z = sin y + 18 x 2 over −y ≤ x ≤ 2 − y 2 , −1 ≤ y ≤ 2. hvsd / Example 3: Solid color with black mesh hvsd / Example 3: Standard color map hvsd / Example 3: Parameter region 2 2 1.5 0.5 0.5 1 0 0.5 0 −0.5 −0.5 −1 2 −1 2 2 1 x = −y 0 2 1 0 0 −1 y y 1 z z x=2−y 1 −2 x 0 0 y −1 −2 −0.5 −1 −2 −1 x 0 x 1 Solution 2. Explicit surface with a triangular parameter region Graph z = + x2 over the region 1 ≤ y ≤ y3 hvsd / Example 2: Standard color map 5 2 − hvsd / Example 2: Solid color with black mesh 1 2 x, 1 Curved boundaries on your parameter region? No problemo! ≤ x ≤ 3. %========== % % hvsd / Example 3: surface pix % syms x y [Z X Y] = hvsd(sin(y + xˆ2/8), [x -y 2-yˆ2 10], [y -1 2 20]); surf(X,Y,Z) figure surf(X,Y,Z, ’FaceColor’, ’m’, ’EdgeColor’, ’k’) % echo off; diary off %========== % % hvsd / Example 3: parameter region in xy-plane % t = linspace(-1, 2, 20); x1 = -t; y1 = t; x1 = fliplr(x1); y1 = fliplr(y1); x2 = 2-t.ˆ2; y2 = t; x = [x1 x2]; y = [y1 y2]; fill(x,y,’g’); grid on; axis equal; axis tight % hold on plot([-2 2], [0 0], ’k’, ’LineWidth’, 2) plot([0 0], [-2 2], ’k’, ’LineWidth’, 2) % hvsd / Example 2: Parameter region 2.5 8 8 6 6 2 y z 10 z 10 4 y = 5/2 − x/2 1.5 4 2 2 2 2 1 3 1.5 y 2 1 1 x 3 1.5 y 2 1 1 x 0.5 0.5 y=1 1 1.5 2 x 2.5 3 3.5 Solution Note the order of the receiving matrices in the code below. The specification of the parameter region is just like you’d set up the the inner and outer ranges for a multiple integral; very natural, eh? %========== % % hvsd / Example 2: surface pix % syms x y [Z Y X] = hvsd(xˆ2 + yˆ3, [y 1 5/2-x/2 20], [x 1 3 20]); surf(X,Y,Z) figure surf(X,Y,Z, ’FaceColor’, ’m’, ’EdgeColor’, ’k’) % echo off; diary off %========== % % hvsd / Example 2: parameter region in xy-plane % % Here we trace the boundary of the filled region in a % clockwise fashion. ‘The tangled webs we weave...’ % echo off; diary off 4. Parametric surface (HCFT: half-cone + flat top, 853/4) Sketch the solid whose volume is given by the integral Z 2π Z π/3 Z sec φ ρ 2 sin φ dρ dφ dθ. 0 2 0 0 Stewart 853/4: HCFT (half−cone, flat top) X = 4 * sin(P) .* cos(T); Y = 4 * sin(P) .* sin(T); Z = 4 * cos(P); %mesh(X,Y,Z, ’FaceColor’, ’r’, ’EdgeColor’, ’k’) surf(X,Y,Z) axis equal % 1 0.8 z 0.6 echo off; diary off 0.4 0.2 0 −1 0 1 1 6. Parametric surface (cone + sphere, 849/62) −1 0 x y Sketch the solid described by the inequalities 0 ≤ φ ≤ ρ ≤ 2. Stewart 849/62: Boy, howdy! Ice cream! % % Stewart 853/4g % p = linspace(0, pi/3, 7); r = linspace(0, 2, 11); t = linspace(0, 2*pi, 28); [P,T] = meshgrid(p,t); rho = sec(P); X = rho .* sin(P) .* cos(T); Y = rho .* sin(P) .* sin(T); Z = rho .* cos(P); mesh(X,Y,Z, ’FaceColor’, ’r’, ’EdgeColor’, ’k’) hold on % [R,T] = meshgrid(r,t); X = R .* sin(pi/3) .* cos(T); Y = R .* sin(pi/3) .* sin(T); Z = R .* cos(pi/3); mesh(X,Y,Z, ’FaceColor’, ’g’, ’EdgeColor’, ’k’) % axis equal % 2 z 1.5 1 0.5 0 −1 0 1 1 0 −1 x y % % Stewart 849/62 % p = linspace(0, pi/3, 7); r = linspace(0, 2, 11); t = linspace(0, 2*pi, 28); [P,T] = meshgrid(p,t); X = 2 * sin(P) .* cos(T); Y = 2 * sin(P) .* sin(T); Z = 2 * cos(P); mesh(X,Y,Z, ’FaceColor’, ’r’, ’EdgeColor’, ’k’) hold on % [R,T] = meshgrid(r,t); X = R .* sin(pi/3) .* cos(T); Y = R .* sin(pi/3) .* sin(T); Z = R .* cos(pi/3); mesh(X,Y,Z, ’FaceColor’, ’y’, ’EdgeColor’, ’k’) axis equal % echo off; diary off 5. Parametric surface (concentric spheres, 848/50) Identify the surface whose equation is ρ 2 − 6ρ + 8 = 0. Stewart 848/50: Mother sphere with baby sphere inside 4 2 echo off; diary off 0 −2 −4 −4 7. Parametric surface (cylinder + hemisphere, 849/65) −2 0 2 y 4 4 2 0 −2 −4 Draw a silo consisting of a cylinder of radius 3 and height 10 surmounted by a hemisphere. x Stewart 849/62: Grain silo % % Stewart 848/50 % p = linspace(0, pi, 19); t = linspace(0, 2*pi, 37); [P,T] = meshgrid(p,t); X = 2 * sin(P) .* cos(T); Y = 2 * sin(P) .* sin(T); Z = 2 * cos(P); mesh(X,Y,Z, ’FaceColor’, ’m’, ’EdgeColor’, ’k’) hold on % p = linspace(0, pi, 19); t = linspace(pi/2, 2*pi, 28); [P,T] = meshgrid(p,t); 12 10 8 z z π, 3 6 4 2 0 2 3 0 −2 y 0 −2 2 x % % Stewart 849/65 % p = linspace(0, pi/2, 10); r = linspace(0, 3, 7); t = linspace(0, 2*pi, 28); z = linspace(0, 10, 6); % [T,Z] = meshgrid(t,z); X = 3*cos(T); Y = 3*sin(T); mesh(X,Y,Z, ’FaceColor’, ’b’, ’EdgeColor’, ’k’) hold on % [P,T] = meshgrid(p,t); X = 3 .* sin(P) .* cos(T); Y = 3 .* sin(P) .* sin(T); Z = 3 .* cos(P) + 10; mesh(X,Y,Z, ’FaceColor’, ’r’, ’EdgeColor’, ’k’) axis equal % t = linspace(0, pi/2, 19); [R,T] = meshgrid(r,t); X1 = R .* sin(pi/4) .* cos(T); Y1 = R .* sin(pi/4) .* sin(T); Z1 = R .* cos(pi/4); mesh(X1,Y1,Z1, ’FaceColor’, ’g’, p = linspace(0, pi/4, 10); [P,T] = meshgrid(p,t); rho = sqrt(18); X2 = rho .* sin(P) .* cos(T); Y2 = rho .* sin(P) .* sin(T); Z2 = rho .* cos(P); mesh(X2,Y2,Z2, ’FaceColor’, ’r’, % p = linspace(0, pi/4, 10); r = linspace(0, sqrt(18), 10); [P,R] = meshgrid(p,r); X3 = R .* sin(P) .* cos(0); Y3 = R .* sin(P) .* sin(0); Z3 = R .* cos(P); mesh(X3,Y3,Z3, ’FaceColor’, ’m’, % X4 = R .* sin(P) .* cos(pi/2); Y4 = R .* sin(P) .* sin(pi/2); Z4 = R .* cos(P); mesh(X4,Y4,Z4, ’FaceColor’, ’y’, % axis equal % echo off; diary off 8. Parametric surface (wedge, 854/36) Evaluate the integral Z 3 Z √9−y 2 Z √18−x 2 −y 2 0 √ 0 x 2 +y 2 ’EdgeColor’, ’k’); hold on ’EdgeColor’, ’k’) ’EdgeColor’, ’k’) ’EdgeColor’, ’k’) echo off; diary off x 2 + y 2 + z 2 dz d x d y 9. Parametric surface (the wedge ‘o‘ stilton, 843/18) by changing to spherical coordinates. Also draw this wedgeshaped region. Use a triple integral to find the volume of the solid E bounded by the elliptic cylinder 4x 2 + z 2 = 4 and the planes y = 0 and y = z + 2. Solution Solution The p region of integration lies in the first octant, with the cone z = x 2 + y 2 below and the sphere x 2 + y 2 + z 2 = 18 above. Here is a picture showing boundary surfaces of the solid. Here are two 3-D views of the solid’s faces, followed by its projection onto the x z-plane. Faces of solid Stewart 854/36 Projection onto xz−plane Backside view 2 2 4 Sphere 1 2 0 1 1 z z xz−plane z 3 0 0 −1 −1 z −1 4 −2 0 2 2 4 0 x 1 y 1 The volume is Z ZZZ 1 dV = V = Cone 0 0 1 2 x 0 2 1 y E p The cone is ρ cos φ = z = x 2 + y 2 = r = ρ sin φ, whence tan φ = 1 or φ = π4 . Switching to spherical coordinates we have Z π/2 Z π/4 Z √18 0 0 0 ρ 2 ·ρ 2 sin φ dρ dφ dθ = −2 −2 −1 −1 2 x 1 Z 0 1 √ 4−4x 2 0 −1 y Z √ −1 − 4−4x 2 0 z+2 0 x 1 1 d y dz d x = 4π ≈ 12.57 cm3 . Here is the code which produced the picture! This is where we have pushed hvsd beyond its design specs; very subtle. . . 486π √ 2 − 1 ≈ 126.485. 5 % % Stewart 843/18g % t = linspace(0, 2*pi, 37); r = linspace(0, 1, 11); [R,T] = meshgrid(r,t); X = R .* cos(T); Z = 2 * R .* sin(T); Y = Z + 2; mesh(X,Y,Z, ’FaceColor’, ’r’, ’EdgeColor’, ’k’) Here is the code which produced the picture! % % Stewart 854/36g % r = linspace(0, sqrt(18), 10); 4 % Y = 0*Y; hold on mesh(X,Y,Z, ’FaceColor’, ’g’, ’EdgeColor’, ’k’) % syms r t y [W Y T] = hvsd(1, [y, 0, 2*sin(t)+2, 10], [t, 0, 2*pi, 37]); X = 1 * cos(T); Z = 2 * sin(T); mesh(X,Y,Z, ’FaceColor’, ’y’, ’EdgeColor’, ’k’) axis equal; view(150,10) % figure t = linspace(0, 2*pi, 37); x = cos(t); y = 2*sin(t); fill(x,y, ’g’); grid on; axis equal axis([-1.5 1.5 -2.5 2.5]); hold on plot([0 0], [-2 2], ’k’) plot([-1 1], [0 0], ’k’) % echo off; diary off 5
© Copyright 2026 Paperzz