spaced_data

# spaced_data - I=h(fx(i fx(i 1/2 Iold Iold=I end...

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

function spaced_data(y,a,b,xx,fx) %Problem 17.5 % %y=anonymous function to be integrated %a=lower limit, b=upper limit %xx=vector of spaced data %fx=cooresponding values for the elements of xx if nargin~=5,error('Must input anonymous function, lower & upper limits'); end % (a) Analytical means syms x %Integral with respect to x. yy=int(y,x,a,b); aa=eval(yy); %Actual value determined analy. fprintf('\n(a) %6.5f\n\n',aa); % (b) Trapezoidal rule, given unequal segments. Only difference is that the % h's here are changing. Iold=0; for i=1:7-1 h=xx(i+1)-xx(i);

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: I=h*(fx(i)+fx(i+1))/2+Iold; Iold=I; end et=abs(((aa-I)/aa)*100); fprintf('(b) %6.5f, et=%5.4f\n\n',I,et); % (c) A combination of the trapezoidal and Simpson's rules wherever % possible to attain the highest accuracy. % Trapezoidal rule h=xx(2)-xx(1); I1=h*(fx(1)+fx(2))/2; % Simpson's 3/8 rule, four equally spaced points xx(2)-xx(5) h=xx(4)-xx(3); I2=(3/8)*h*(fx(2)+3*fx(3)+3*fx(4)+fx(5)); % Simpson's 1/3 rule, three equally spaced points xx(5)-xx(7) h=xx(7)-xx(6); I3=(h/3)*(fx(5)+4*fx(6)+fx(7)); Itotal=I1+I2+I3...
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

spaced_data - I=h(fx(i fx(i 1/2 Iold Iold=I end...

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

View Full Document
Ask a homework question - tutors are online