

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


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.
(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).
(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
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?
(a) Write a Matlab code T riDiagSolver(A, b) to solve the tridiagonal linear system Ax = b
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:
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.