2. Cartesian boundary functions y = f(x)
We draw and find the area of the region enclosed by the parabola y = ( x − 2 )
2 and line y = x ; area: 4 .
5 cm
2
.
Supplement 7: Problem 2
5
4
Nice figures of regions in the plane may be rendered with
MATLAB via fill and plot commands. The fill command paints the interior of the region with a solid color, whereas plot is used to draw the boundary of the region. Illustrate intersections of boundary pieces by plotting individual points (using filled in circles for the marker type).
3
2
1
0
-1
-1 0 1 2 x
3 4 5
• In Chapter 3 of Gilat, review mathematical operations with arrays. (Use the vectorize command to make element-by-element operations easy!)
3. Parametric boundary curve r( t ) = [ x(t), y(t) ]
• Concatenate vectors to join boundary pieces.
• The fliplr command is useful for traversing the boundary in a counterclockwise fashion.
MATLAB diary files (input and output via echo on ) appear on the reverse. Below just look at the pretty pictures!
1. First paint the area with fill .
2. Then draw the boundary with plot command(s).
4. Add axes, labels, annotation as desired.
closed
3. Highlight intersections with plot using filled in circles for the marker type.
An ellipse
( x − h ) a 2
2
+
( y − b 2 k )
2
= 1 with center ( h , k ) and semi-axis lengths a and b may be parameterized in terms of t as x = h + a cos t , y = k + b sin t , 0 ≤ t ≤ 2
π
. [Note that if a = b we have a circle of radius a with center ( h , k ) .]
Supplement 7, Problem 3
5
4
0
-1
3
2
1
-2
-3
-3 -2 -1 0 1 2 3 4 5 6 7 x
1. Cartesian boundary functions x = g(y)
We draw and find the area of the region enclosed by the parabolas x = 2 y − y
2 and x = y
2 − 4 y ; area: 9 cm
2
.
Supplement 7: Problem 1
4
2
4. Regions bounded by Cartesian curve, coordinate axis, and tangent/normal line
Find the area of the region bounded by the parabola y = x
2
, the normal line to the parabola at ( 2 , 4 ) , and the x -axis.
(The normal line to a curve C at a point P is the line through P that is perpendicular to the tangent line at P .
The slopes of these two lines are negative reciprocals.)
Supplement 7: Problem 4
5
0
-4 -2 x
0 2
0
0 5 x
10 15 20
1
::::::::::::::
Supp07x1/Supp07x1.txt
:::::::::::::: delete Supp07x1.txt; diary Supp07x1.txt
clear; clc; close all; echo on
%
% Supplement 7: Problem 1
%
% Area of region bounded by parabolas syms y % symbolics x1 = 2*y - y^2; x2 = y^2 - 4*y; y_at_intersections = solve(x1 == x2, y) y_at_intersections =
0
3
A = int(x1-x2, y, 0, 3) % cm^2
A =
9
% PLOT OF REGION USING AREA FILL!
y = linspace(0,3); s = vectorize(x1)
% automatic element-by-element operations!
s =
2.*y - y.^2 x1 = eval(s); % convert to numbers x2 = eval(vectorize(x2)); % Or nest ’em!
%
X = [x1 fliplr(x2)];
% Traverse boundary counterclockwise.
Y = [y fliplr(y)]; % corresponding y-values
% fill(X,Y,’y’); grid on; hold on
% Do fill FIRST. Paint it yellow.
plot(X,Y, ’LineWidth’, 2)
% Then do boundary; make it thicker.
plot([0 -3], [0 3], ’mo’, ...
’MarkerFaceColor’, ’m’, ’MarkerSize’, 12)
% intersections points; beauty, eh?
% plot([-5 2], [0 0], ’k’) % Add axes plot([0 0], [-1 4], ’k’) % in black.
xlabel(’x’); ylabel(’y’) % Slap on labels.
% title(’Supplement 7: Problem 1’) axis equal; axis([-5 2 -1 4])
% equal scaling, nicely framed set(gca, ’Xtick’, -4:2:2) % custom xset(gca, ’Ytick’, 0:2:4) % and y-tick marks
% echo off; diary off
::::::::::::::
Supp07x2/Supp07x2.txt
:::::::::::::: delete Supp07x2.txt; diary Supp07x2.txt
clear; clc; close all; echo on
%
% Supplement 7: Problem 2
%
% Area of region bounded by parabola and line syms x % symbolics y1 = (x-2)^2;
2 y2 = x; x_at_intersections = solve(y1 == y2, x) x_at_intersections =
1
4
A = int(y2-y1, x, 1, 4) % cm^2
A =
9/2
A_decimal = double(A) % cm^2
A_decimal =
4.5000
% PLOT OF REGION USING AREA FILL!
x = linspace(1,4); y1 = eval(vectorize(y1)); y2 = eval(vectorize(y2));
X = [x fliplr(x)];
% Traverse boundary counterclockwise.
Y = [y1 fliplr(y2)];
% fill(X,Y,’g’); grid on; hold on
% Do fill FIRST. Paint it green.
plot(X,Y,’b’, ’LineWidth’, 2) plot([1 4], [1 4], ’mo’, ...
’MarkerFaceColor’, ’m’, ’MarkerSize’, 12)
% plot([-1 5], [0 0], ’k’) % Embellishments plot([0 0], [-1 5], ’k’) xlabel(’x’); ylabel(’y’)
% title(’Supplement 7: Problem 2’) axis equal; axis([-1 5 -1 5])
% equal scaling, nicely framed set(gca, ’Xtick’, -1:5) set(gca, ’Ytick’, -1:5)
% echo off; diary off
::::::::::::::
Supp07x3/Supp07x3.txt
:::::::::::::: delete Supp07x3.txt; diary Supp07x3.txt
clear; clc; close all; echo on
%
% Supplement 7, Problem 3
% t = linspace(0,2*pi); x = 2 + 4*cos(t); y = 1 + 2.5*sin(t); fill(x,y,’r’); grid on; hold on plot(x,y, ’LineWidth’, 3) plot([-3 7], [0 0], ’k’) plot([0 0], [-3 5], ’k’) plot([-3 7], [1 1], ’k--’) plot([2 2], [-3 5], ’k--’) plot(2,1,’ko’, ’MarkerFaceColor’, ’k’) xlabel(’x’); ylabel(’y’) title(’Supplement 7, Problem 3’) axis equal; axis([-3 7 -3 5]) set(gca, ’Xtick’, -3:7) set(gca, ’Ytick’, -3:5)
% echo off; diary off