hw13_solutions

# hw13_solutions - b =[pi/9 sqrt(3/2 sqrt(3/2-pi/9 N =...

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

Section 2.4

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

View Full Document
Section2.5
Problem 3 (2.5 11a) %% section 2.5 11a clear close all clc h = 2.^(-1:-1:-7); N = 1./h; for k = 1:7 I = 0.2*atan(5); %%%%%%%% left-endpoint rectangular rule %%%%%%%%% x1 = 0:h(k):1-h(k); fx1 = 1./(1 + 25*x1.^2); T1(k) = h(k)*sum(fx1); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%% trapezoid rule %%%%%%%%%%%%%%% x2 = 0:h(k):1; fx2 = 1./(1 + 25*x2.^2); T2(k) = h(k)/2*(fx2(1) + 2*sum(fx2(2:end-1)) + fx2(end)); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end err1 = T1 - I; err2 = T2 - I; figure plot(log(h),log(abs(err1))); hold on plot(log(h),log(abs(err2)), 'r' ); legend( 'left-endpoint' , 'trapeziod' ) xlabel( 'h' ) ylabel( 'error' ) grid on -5 -4 -3 -2 -1 0 -15 -10 -5 0 h error left-endpoint trapeziod

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

View Full Document
Section 2.6 2. The answer from matlab code is below x = 0.008494710254722 0.157543504689989 0.227356674769762 -0.200944799984597 The code is below %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% section 2.6 2 clear clc close all l = [0 1 1 2]; d = [4 4 4 4]; u = [2 1 1 0];

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: b = [pi/9, sqrt(3)/2 sqrt(3)/2 -pi/9]; N = length(d); x = zeros(N,1); for k = 2:N d(k) = d(k) - u(k-1)*l(k)/d(k-1); b(k) = b(k) - b(k-1)*l(k)/d(k-1); end x(N) = b(N)/d(N); for k = N-1:-1:1 x(k) = (b(k) - u(k)*x(k+1))/d(k); end display(x) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Section 2.7 3 The answer from matlab is below x = 0.018336695058824 0.035006775977942 0.048317587771715 0.056523986874421 0.057801073272040 0.050215676439535 0.031696149551397 The code is here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 %% section 2.7 3 clear clc close all M = 8; N = M-1; h = 1/M; l = -1*ones(N,1); l(1) = 0; d = ones(N,1)*(2+h^2); u = -1*ones(N,1); u(end) = 0; b = (h:h:N*h)*h^2; x = zeros(N,1); for k = 2:N d(k) = d(k) - u(k-1)*l(k)/d(k-1); b(k) = b(k) - b(k-1)*l(k)/d(k-1); end x(N) = b(N)/d(N); for k = N-1:-1:1 x(k) = (b(k) - u(k)*x(k+1))/d(k); end display(x) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Created by Jianjian Gao 2010/10/12...
View Full Document

{[ snackBarMessage ]}

### Page1 / 7

hw13_solutions - b =[pi/9 sqrt(3/2 sqrt(3/2-pi/9 N =...

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

View Full Document
Ask a homework question - tutors are online