24.03.2013 Views

Chapter 3 Solution of Linear Systems - Math/CS

Chapter 3 Solution of Linear Systems - Math/CS

Chapter 3 Solution of Linear Systems - Math/CS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

78 CHAPTER 3. SOLUTION OF LINEAR SYSTEMS<br />

Problem 3.5.8. Implement the function gepp, and use it to solve the linear systems given in<br />

problems 3.2.2 and 3.2.3.<br />

Problem 3.5.9. Test gepp using the linear system<br />

⎡<br />

1 2<br />

⎤ ⎡<br />

3<br />

⎣ 4 5 6 ⎦ ⎣<br />

7 8 9<br />

Explain your results.<br />

x1<br />

x2<br />

x3<br />

⎤<br />

⎡<br />

⎦ = ⎣<br />

Problem 3.5.10. Modify gepp, replacing the statements if abs(A(k,k)) < tol and if abs(A(n,n))<br />

< tol with, respectively, if A(k,k) == 0 and if A(n,n) == 0. Solve the linear system given in<br />

problem 3.5.9. Why are these results different than those computed in problem 3.5.9?<br />

Problem 3.5.11. The built-in Matlab function hilb can be used to construct the so-called Hilbert<br />

matrix, whose (i, j) entry is 1/(i + j − 1). Write a script M-file that constructs a series <strong>of</strong> test<br />

problems <strong>of</strong> the form:<br />

A = hilb(n);<br />

x_true = ones(n,1);<br />

b = A*x_true;<br />

The script should use gepp to solve the resulting linear systems, and print a table <strong>of</strong> results with the<br />

following information:<br />

where<br />

----------------------------------------------------n<br />

error residual condition number<br />

-----------------------------------------------------<br />

• error = relative error = norm(x true - x)/norm(x true)<br />

• residual = relative residual error = norm(b - A*x)/norm(b)<br />

• condition number = measure <strong>of</strong> conditioning = cond(A)<br />

Print a table <strong>of</strong> results for n = 5, 6, . . . , 13. Are the computed residual errors small? What about the<br />

relative errors? Is the size <strong>of</strong> the residual error related to the condition number? What about the<br />

relative error? Now try to run the script with n ≥ 14. What do you observe?<br />

Problem 3.5.12. Rewrite the function gepp so that it does not use array operations. Compare the<br />

efficiency (e.g., using tic and toc) <strong>of</strong> this function with gepp on matrices <strong>of</strong> various dimensions.<br />

3.5.4 Built-in Matlab Tools for <strong>Linear</strong> <strong>Systems</strong><br />

An advantage <strong>of</strong> using a powerful scientific computing environment like Matlab is that we do<br />

not need to write our own implementations <strong>of</strong> standard algorithms, like Gaussian elimination and<br />

triangular solves. Matlab provides two powerful tools for solving linear systems:<br />

• The backslash operator: \<br />

Given a matrix A and vector b, this operator can be used to solve Ax = b with the single<br />

command:<br />

x = A \ b;<br />

1<br />

0<br />

1<br />

⎤<br />

⎦ .

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!