# Rom_gquad - x=9; break end end if x==9 %Need this if...

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

function Rom_gquad(y,b,a,e) % Problem 18.3 % %I=function that is to be integrated, e= error tolerance, %b=upper limit, a=lower limit. %Actual value for integrated function with a and b syms x yy=int(y,x,a,b); aa=eval(yy); %Actual value determined analy. if nargin~=4,error('requires function,upper & lower limits, and error'); end %-------------------------------------------------- % Trapezoidal rule for 50 segments ynew=0; n=1; for j=1:50 yold=0; h=(b-a)/n; for i=1:n-1 h2=h*i; ynew=y(a+h2)+yold; yold=ynew; end I(n)=(b-a)*(y(a)+2*ynew+y(b))/(n*2); n=n+1; end %-------------------------------------------------- %(a) Romberg integration I2=zeros(49,1); %preallocating for speed j=1; k=49; while(1) for i=1:k I2(i)=(4^j*I(i+1)-I(i))/(4^j-1); ea=abs((I2(i)-I(i+1))/I2(i))*100; et=abs((aa-I2(i))/aa)*100; if ea<e d I2(i) et ea

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

View Full Document
fprintf('\(a) %10.8f, ea=%5.4f, et=%5.4f\n\n',I2(i),ea,et);
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x=9; break end end if x==9 %Need this if statment because the first break only %gets out or the for loop. break end I=I2; j=j+1; k=k-1; end %--------------------------------------------------% (b) two-point Gauss quadrature formula (or Gauss-Legendre),integral % estimate that is third-order accurate. a1=(b+a)/2; a2=(b-a)/2; y2=@(x) ((a1+a2*x)*exp(a1+a2*x))*a2; yy=y2(-1/sqrt(3))+y2(1/sqrt(3)); et=abs((aa-yy)/aa)*100; fprintf('\n(b) %9.7f, et=%2.1f\n\n',yy,et); %--------------------------------------------------% (c) MATLAB quad and quadl functions q=quad(y,a,b); et=abs((aa-q)/aa)*100; q2=quadl(y,a,b); et2=abs((aa-q2)/aa)*100; fprintf('\n(c)quad solution %16.14f, et=%2.1e\n quadl solution %16.14f, et=%2.1e\ n\n',q,et,q2,et2)...
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

Rom_gquad - x=9; break end end if x==9 %Need this if...

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

View Full Document
Ask a homework question - tutors are online