Solution5

Solution5 - ChE 132B HW5 Solutions 100pt Problem 1(5pt%HW5#1 x0=-1;x1=1;x2=2 L0=(x(x-x1(x-x2(x0-x1(x0-x2 L1=(x(x-x0(x-x2(x1-x0(x1-x2

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ChE 132B HW5 Solutions 100pt Problem 1. (5pt) %HW5 #1 x0=-1;x1=1;x2=2; L0=@(x) (x-x1).*(x-x2)./((x0-x1).*(x0-x2)); L1=@(x) (x-x0).*(x-x2)./((x1-x0).*(x1-x2)); L2=@(x) (x-x0).*(x-x1)./((x2-x0).*(x2-x1)); x=-1:0.1:2; plot(x,L0(x),x,L1(x),x,L2(x)) legend( 'L0' , 'L1' , 'L2' ) xlabel( 'x' ) ylabel( 'y' ) title( 'HW5 #1' ) Problem 2. (5pt) For N=2, the Chebyshev points are : = 1, 1 = 0, 2 = − 1 (1) The Chebyshev polynomials are : = 1, 1 = , 2 = 2 2 − 1 (2) Plug Eq.(2) into = ∑ ( ) =0 , = + 1 + 2 (2 2 − 1) (3) At x , x 1 , and x 2 , the values of y(x) are : ( ) = = + 1 + 2 ( 1 ) = 1 = − 2 ( 2 ) = 2 = − 1 + 2 (4) Solve the above system of equation with respect to the Chebyshev polynomial coefficients, = 4 + 1 2 + 2 4 1 = − 2 2 2 = − 1 2 − − 2 4 (5) Differentiate Eq.(3) and plug the Chebyshev polynomial coefficients into it, ′ = 1 + 4 2 (6) ′ = 2 − 2 2 + − 2 1 + 2 4 ¡ (7) At x ,x 1 , and x 2 , the values of y’(x) are : ′ ( ) = 3 2 − 2 1 + 2 2 ′ ( 1 ) = 2 − 2 2 ′ ( 2 ) = − 2 + 2 1 − 3 2 2 (8) In matrix form, ′ 1 ′ 2 ′ ¡ = ⎣ ⎢ ⎢ ⎢ ⎢ ⎡ 3 2 − 2 1 2 1 2 − 1 2 − 1 2 2 − 3 2 ⎦ ⎥ ⎥ ⎥ ⎥ ⎤ ¢ 1 2 £ (9) Finally, the Chebyshev differentiation matrix for N=2 is : 2 = ⎣ ⎢ ⎢ ⎢ ⎢ ⎡ 3 2 − 2 1 2 1 2 − 1 2 − 1 2 2 − 3 2 ⎦ ⎥ ⎥ ⎥ ⎥ ⎤ (10) Eq.(10) is confirmed using chebD.m >> chebD(2) ans = 1.5000 -2.0000 0.5000 0.5000 0 -0.5000 -0.5000 2.0000 -1.5000 Problem 3. (20pt) % HW5 3.a (5pt) n=16; xfine = 0:.005:1; clf % a fine grid x = (0:n)/n; % x data values, equally spaced y = sin(2.*x).*cos(5.*x); % y values of data yfine = sin(2.*xfine).*cos(5.*xfine); % "exact" function on fine grid yfit = interp1(x,y,xfine, 'spline' ); plot(x,y, '.' , 'markersize' ,13) line(xfine,yfit) axis([0 1 -1 1]), title( 'HW5 #3.(a)' ) xlabel( 'x' ), ylabel( 'y' ) error = norm(yfine-yfit,inf); text(.5,.5,[ 'max error = ' num2str(error)]) %HW5 3.b(5pt) n=16; xfine = 0:.005:1; clf % a fine grid x = cos(pi*(0:n)/n); % Chebyshev points % rescale the inverval x=(x+1)./2; y = sin(2.*x).*cos(5.*x); % y values of data yfine = sin(2.*xfine).*cos(5.*xfine); % "exact" function on fine grid p = polyfit(x,y,n); % This is our fit to a degree n polynomial yfit = polyval(p,xfine); % This evaluates the polynomial at our fine x values...
View Full Document

This note was uploaded on 02/12/2012 for the course CHE 132b taught by Professor Ceweb during the Fall '09 term at UCSB.

Page1 / 15

Solution5 - ChE 132B HW5 Solutions 100pt Problem 1(5pt%HW5#1 x0=-1;x1=1;x2=2 L0=(x(x-x1(x-x2(x0-x1(x0-x2 L1=(x(x-x0(x-x2(x1-x0(x1-x2

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

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