hw8_solutions - CS 257 Numerical Methods - Homework 8...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 257 Numerical Methods - Homework 8 November 10, 2006 1. [1pt] 6.2#1 (Compute by hand) Solution: The first step is to change intervals using a linear transformation. Let x = t + 1. In this case Z 2 0 e - x 2 dx = Z 1 - 1 e - ( t +1) 2 dt Now we use the first order Gaussian Quadrature to approximate the right hand integral. e - ( - 1 3 +1) 2 + e - ( 1 3 +1) 2 Numerically computing the above value yields the following result. Z 2 0 e - x 2 dx 0 . 9195 2. [1pt] 6.2c#1 Solution: The important step here is to remember to transform the interval from [ a, b ] to [ - 1 , 1]. function I = threeNodeGauss(f,a,b) m = (b-a)/2; b = (a+b)/2; n = [-sqrt(3/5), 0 , sqrt(3/5)]; I = m*(5/9*f(m*n(1)+b) + 8/9*f(m*n(2)+b) + 5/9*f(m*n(3)+b)); 3. [1pt] 6.2c#2 Solution: (a) >> threeNodeGauss(inline(’1/sqrt(x)’),0,1) ans = 1.7509 (b) >> threeNodeGauss(inline(’exp(-cos(x)^2)’),0,2) ans = 1.4119 4. [1pt] 6.2c#10 (Use gaussQuad.m from class if you wish) Solution: Part A: Nodes Approx Error 2 -1.5471 9.7814e-02 3 -1.5943 5.0673e-02 4 -1.6141 3.0856e-02 5 -1.6242 2.0726e-02 6 -1.6301 1.4869e-02 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Part B: Nodes Approx Error 2 0.8222 -2.2470e-04 3 0.8225 -4.9368e-06 4 0.8225 -1.1590e-07 5 0.8225 -2.8372e-09 6 0.8225 -7.1480e-11 Part C: Nodes Approx Error 2 0.4100 -1.2310e-03 3 0.4113 2.0839e-05 4 0.4112 5.6472e-07 5 0.4112 -5.9589e-08 6 0.4112 2.2814e-09 These results were generated by the following MATLAB script. for i = 1:3 switch i case 1 f = inline(’log(1-x)./x’); exact = -pi^2/6; case 2 f = inline(’log(1+x)./x’); exact = pi^2/12; case 3 f = inline(’log(1+x.^2)./x’); exact = pi^2/24; end fprintf(’\nPart %c:\n’,’A’+i-1); fprintf(’%10s%15s%15s\n’,’Nodes’,’Approx’,’Error’); for j = 1:5 approx = gaussQuad(f,0,1,1,j); fprintf(’%10d%15.4f%15.4e\n’,j+1,approx,approx-exact); end end 5. [1pt] 9.2#4 Solution: The first step is to write out the spline and its derivatives S ( x ) = ± a + b ( x - 1) + c ( x - 1) 2 + d ( x - 1) 3 x [0 , 1] ( x - 1) 3 + ex 2 - 1 x [1 , 2] S 0 ( x ) = ± b + 2 c
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/15/2008 for the course CS 257 taught by Professor Thomaskerkhoven during the Fall '05 term at University of Illinois at Urbana–Champaign.

Page1 / 6

hw8_solutions - CS 257 Numerical Methods - Homework 8...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online