Docsity

Scientific Computing - Homework 9 Problems - Fall 2009 | CSCI 407, Assignments of Computer Science

Toggle sidebar
bg1
Homework #9 for MATH/CSCI 407
Due at the beginning of class, April 20th, 2009
There are three problems in total (100 points). Please summarize your plots and results concisely. Please
attach your MATLAB code in separate sheets.
1. (20 (= 8+6+6) points)
(a) Find the solution for the following triangular system
100
120
123
x1
x2
x3
1
2
3
313
022
001
x1
x2
x3
1
2
3
(b) Write a Matlab code x=LTriSol(A, b), whose input is any lower triangular n-by-n matrix Aand
vector b, to solve for Ax=b. Check your code by solving the lower triangular system in Part
(a).
(c) Write a Matlab code x=UTriSol(A, b), whose input is any upper triangular n-by-n matrix Aand
vector b, to solve for Ax=b. Check your code by solving the upper triangular system in Part
(a).
2. (40 (= 6 + 14 + 10 + 10) points)
(a) Find the solution for the following linear system
123
−1−3−3
1−2 1
x1
x2
x3
1
−1
2
(b) Write a Matlab code [L, U] = LUfactorization(A), whose input is any n-by-n matrix Aand the
output is the matrix Land Uas the LU factorization of A. Measure the CPU time (you could
search for the use of ‘tic’ and ‘toc’ in Matlab Help). Check your code by solving the linear system
in Part (a) by the following procedure
[L, U] = LUFactorization(A)
y = LTriSol(L, b)
x = UTriSol(U, y)
(c) Use your code to solve Ax=bwith
A=1
1 1
and b= (1,2)0, with = 0,10−13,10−15 ,10−17. What are your solutions xfor different ? Small
can be viewed as a small perturbation of the matrix
A=0 1
1 1
Are your solutions for different close to each other? What is the problem?
(d) The Gaussian elimination with pivoting can stabilize the algorithm. Write a new Matlab code
and solve for examples in Part (c) again. How does your solution look now?
1
pf2

Partial preview of the text

Download Scientific Computing - Homework 9 Problems - Fall 2009 | CSCI 407 and more Assignments Computer Science in PDF only on Docsity!

Homework #9 for MATH/CSCI 407

Due at the beginning of class, April 20th, 2009

There are three problems in total (100 points). Please summarize your plots and results concisely. Please attach your MATLAB code in separate sheets.

  1. (20 (= 8+6+6) points)

(a) Find the solution for the following triangular system  

x 1 x 2 x 3

x 1 x 2 x 3

(b) Write a Matlab code x=LTriSol(A, b), whose input is any lower triangular n-by-n matrix A and vector b, to solve for Ax = b. Check your code by solving the lower triangular system in Part (a). (c) Write a Matlab code x=UTriSol(A, b), whose input is any upper triangular n-by-n matrix A and vector b, to solve for Ax = b. Check your code by solving the upper triangular system in Part (a).

  1. (40 (= 6 + 14 + 10 + 10) points)

(a) Find the solution for the following linear system  

x 1 x 2 x 3

(b) Write a Matlab code [L, U] = LUfactorization(A), whose input is any n-by-n matrix A and the output is the matrix L and U as the LU factorization of A. Measure the CPU time (you could search for the use of ‘tic’ and ‘toc’ in Matlab Help). Check your code by solving the linear system in Part (a) by the following procedure

[L, U] = LUFactorization(A) y = LTriSol(L, b) x = UTriSol(U, y)

(c) Use your code to solve Ax = b with A =

and b = (1, 2)′, with  = 0, 10 −^13 , 10 −^15 , 10 −^17. What are your solutions x for different ? Small  can be viewed as a small perturbation of the matrix

A =

Are your solutions for different  close to each other? What is the problem? (d) The Gaussian elimination with pivoting can stabilize the algorithm. Write a new Matlab code and solve for examples in Part (c) again. How does your solution look now?

  1. (40 (= 10+10+10+10) points)

(a) Write a Matlab code T riDiagSolver(A, b) to solve the tridiagonal linear system Ax = b

A =

d 1 c 1 0 · · · 0 0 a 2 d 2 c 2 · · · 0 0 0 a 3 d 3 · · · 0 0 .. .

0 0 0 · · · dn− 1 cn− 1 0 0 0 · · · an dn

by an order N procedure (see page 6 to page 8 of lecture notes for reference). In your code, please measure the CPU time it takes. (b) Test your code by using the following example:

A =

h^2

n×n

with h = ( (^) n^2 +1π ), and

b = (cos(

2 π n + 1

), cos(

2 π n + 1

) · · · cos(n

2 π n + 1

i.e. bi = cos(i (^) n^2 +1π ). Solve Ax = b by your code for n = 15, 25 , 45 , 75 , 150. For each n, let

y = ( 2 π n + 1

2 π n + 1

· · · , n 2 π n + 1

Use the Mablab to plot y vs. x as plot(y, x) On the same plot, plot(y, b). You will need to produce 5 plots (for different n) in the end. (c) What do you observe in your plots? Why? (Hint: it is related to the second order numerical differentiation.) (d) Solve Ax = b by your code ‘TriDiagSolver’ for n = 1200 and measure the CPU time it takes. At the same time, use your Matlab code ‘LUFactorization’ to solve the same system of equations and measure the CPU time it takes. Are the solutions you obtained from the two code the same? How do you compare the CPU time? Explain what you observe.