Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

2023T1 MATH2089 – Numerical Methods Tutorial Problems (MATLAB*)

Week 2

*Python version for this tutorial is available as a Jupyter notebook from the course Moodle page. Topic:  §1 Numerical Computing (continued), §2 Linear Systems

1.  [M] The easiest way to deine a simple function in Matlab is to use an anonymous function.

(a)  Write an anonymous function myf to evaluate f(x) = e x2 .

(b)  Create a vector x of 21 equally spaced points on [3, 3] (Hint:  linspace).

(c)  Use your anonymous function to plot f on [ 3, 3].  Does it look correct?

(d)  Repeat using 101 points.

(e)  Zoom in (Magnifying glass with a + at the top of the igure window) around x = 0.

2.  [M] The standard expressions for the solutions of the quadratic equation ax2 + bx + c = 0 are

b +^b2  4ac   ()

r2  =    (♥)

r1  =             2c          ()

r2  =    (♣)

If a and c are much smaller in magnitude compared to b, then

. When b > 0, the numerically preferable expressions are () and ().

. When b < 0, the numerically preferable expressions are (♠) and (♣).

(a)  Write and test a Matlab function quadsolve to solve the quadratic in a numerically stable way. The function must be in the ile quadsolve.m.  The speciications are

[r1, r2] = quadsolve(a, b, c)

Include comments at the beginning of your function giving the calling sequence and the purpose of the function.

(b)  Write a Matlab M-ile to test your function quadsolve on a range of examples, including

i.  x2 + 3x + 2 = 0

ii.  0 .01x2 + 2000x 0 .001 = 0

iii .  x2  1 = 0

iv .  a = 1,b = 200,c = 0 .000015  (example in Wikipedia)

v.  Any other cases you can think of?

3.  [M] Let x = (5, −4, 0, −6)T .  Calculate |x|1 , |x|2  and |x|∞  by hand and check your answers

4.  [M] Let

A =  l 0(3)   4(4)   5(2) 

5.  [M] Consider the matrices

A =  「(l)1

3

4

2

26   ,


B =  l

1/16


5/32


1/32

(a)  Verify that B = A1  by showing that AB = I . What is |AB I|1 ?

(b)  Calculate  |A|1 ,  |A1|1  and κ 1 (A) by hand and check using Matlab.

(c)  Calculate |A|, |A1|and κ(A) by hand and check using Matlab.

(d)  You want to calculate the 2-norm condition number κ2 (A) = |A|2  |A1|2 .

i.  Use MATLAB’s cond to calculate κ2 (A).

ii.  Use the Matlab function eig to calculate the eigenvalues of A and A1 .

iii.  How are the eigenvalues of A and A1  related?

iv.  If λ 1 ,λ2 ,λ3  denote the eigenvalues of A, calculate

max1i3 |λi | min1i3 |λi | .

Is this the same as κ2 (A)?

(e)  The LU factorization produces a lower triangular matrix L and an upper triangular matrix U such that

PA = LU

where P is a permutation matrix reordering the rows of A (equations in a linear system).

i.  Use the Matlab function lu to calculate the matrices P , L, and U .

ii.  Calculate E = PA LU and  |E|2 .

(f)  Use the LU factorization to solve the linear system Ax = b for b = (1, 2, 3).