double_integral

# double_integral - et=abs(((a-I)/a)*100); %fprintf('(b) %1d,...

This preview shows pages 1–2. Sign up to view the full content.

function double_integral(d,u1,l1,u2,l2) %Problem 17.6 % % (a) Evaluate double integral analytically, note: imagine the integration % as two sweeping motions. Inner integration, a vertical line sweeps out % the area of a cross section. For the outer integration, the cross section % sweeps out the volume. if nargin~=5, error('Must specify a function to be integrated'); end syms x %Evaluates double integral with respect to x. yy1=int(d,x,l1,u1); syms y %Evaluates double integral with respect to y. yy2=int(yy1,y,l2,u2); a=eval(yy2); fprintf('\n%7.6f\n\n',a); % (b) Using the composite trapezoidal rule with n=2 n=2; h=(u1-l1)/n; % Need to first implement along the x-dimension for each y value l3=l2; i=d(l1,l2); j=d(h,l2); k=d(u1,l2); for s=1:3 y(s)=(u1-l1)*(i+2*j+k)/(2*n); l3=l3+h; i=d(l1,l3); j=d(h,l3); k=d(u1,l3); end I=(u2-l2)*(y(3)+2*y(2)+y(1))/(n*2);

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: et=abs(((a-I)/a)*100); %fprintf('(b) %1d, et=%2d',I,et); %??? Error using ==> fprintf disp('(b)'); %Function is not defined for 'sym' inputs. disp(I); disp('error'); disp(et); % (c) Using single applications of Simpson's Rule %Note: Simpson's 1/3 rule yields perfect results for cubic polynomials. n=2; h=(u1-l1)/n; % Need to first implement along the x-dimension for each y value l3=l2; i=d(l1,l2); j=d(h,l2); k=d(u1,l2); for s=1:3 y(s)=(u1-l1)*(i+4*j+k)/(3*n); l3=l3+h; i=d(l1,l3); j=d(h,l3); k=d(u1,l3); end I=(u2-l2)*(y(3)+4*y(2)+y(1))/(n*3); disp('(c)'); et=abs(((a-I)/a)*100); aa=eval(I); disp(aa); disp('error'); disp(et); %fprintf('(c) %7.6f, et=%1d\n\n',aa,et); %??? Error using ==> fprintf %Function is not defined for 'sym' %inputs....
View Full Document

## This note was uploaded on 09/27/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

### Page1 / 2

double_integral - et=abs(((a-I)/a)*100); %fprintf('(b) %1d,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online