Chapter17

# Chapter17 - Problem 17.3/2 Given the integral(6 3cos x)dx(6...

This preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Problem 17.3. /2 Given the integral (6 3cos x)dx (6 x 3sin x) | 0 /2 0 3 3 12.4247 Evaluate it using 4 equally spaced points in the integration interval We first generate the data >> f=@(x) 6+3*cos(x) f = @(x)6+3*cos(x) >> x=linspace(0,pi/2,4) x = 0 0.5236 1.0472 1.5708 >> y=f(x) y = 9.0000 8.5981 7.5000 6.0000 We can first integrate using trapezoidal integration >> trapez=(pi/12)*(y(1)+2*y(2)+2*y(3)+y(4)) trapez = 12.3559 Or >> trapez=trapz(x,y) trapez = 12.3559 For an error of 0.0688 Or we can use Simpson rule on the first two points, and trapezoidal rule on the last two. The interval for Simpson rule is 2/3 of the original interval or pi/3. >> Simp=(pi/18)*(y(1)+4*y(2)+y(3))+(pi/12)*(y(3)+y(4)) Simp = 12.4167 With an error of 0.008. Or we can fit the data with a polynomial or a spline, and then use a very dense grid to integrate with trapezoidal rule. >> xx=linspace(0,pi/2); >> yy=polyval(p,xx); >> trapezfit=trapz(xx,yy) trapezfit = 12.4277 With an error of 0.004. We can check if the error is due to the fit or the limited number (100) of points by doubling the number of points. >> xx=linspace(0,pi/2,200); >> yy=polyval(p,xx); >> trapezfit=trapz(xx,yy) trapezfit = 12.4278 So the error is due to the fit. For this problem, we get the same result with other fits: >> yy1=interp1(x,y,xx,'cubic'); >> trapezcub=trapz(xx,yy1) trapezcub = 12.4278 >> yy1=interp1(x,y,xx,'spline'); >> trapezcub=trapz(xx,yy1) trapezcub = 12.4278 ...
View Full Document

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

Ask a homework question - tutors are online