HW 7
25.1)
By changing line 194 to
z = (x + y)./(x.^2 + y.^2)
and commenting out lines 195 and
196 in mywasher, the following 3D plot is obtained:
Now, in mywedge, once we change line 40 to
z = sin(x) + sqrt(y)
and comment out line 41, this is
the 3D plot that we get:
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
25.2)
The following is the code for mycenters:
function
I = mycenters(f,V,T)
% Integrates a function based on a triangulation, using three corners
% Inputs: f  the function to integrate, as an inline
% V  the vertices. Each row has the x and y coordinates of a vertex
% T  the triangulation. Each row gives the indices of three corners
% Output: the approximate integral
x = V(:,1);
% extract x and y coordinates of all nodes
y = V(:,2);
I=0;
p = size(T,1);
for
i = 1:p
x1 = x(T(i,1));
% find coordinates and area
x2 = x(T(i,2));
x3 = x(T(i,3));
y1 = y(T(i,1));
y2 = y(T(i,2));
y3 = y(T(i,3));
A = .5*abs(det([x1, x2, x3; y1, y2, y3; 1, 1, 1]));
xbar = (x1 + x2 + x3)/3;
ybar = (y1 + y2 + y3)/3;
zavg = f(xbar,ybar);
I = I + zavg*A;
% accumulate integral
end
Now, let us use mycenters to find the volume under the surfaces created in 25.1.
For the volume created
with mywedge, we use the following MatLab commands:
>> f = inline('sin(x) + sqrt(y)','x','y')
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 Staff
 Numerical Analysis, Inline function, 512, mywedge, mywasher

Click to edit the document details