Docsity

Engineering Mathematics Lab Exercise: Conditioning and Iteration, Lecture notes of Engineering Mathematics

Toggle sidebar
bg1
Second Year Engineering Mathematics
Laboratory
Exercise 1: Conditioning and iteration
Michaelmas Term
A: Conditioning of matrix-vector equations
The purpose of this exercise is to introduce you to the concepts of matrix and vector
`norms' and the concept of ill-conditioned systems. This is shown using simple examples
of sumultaneous linear equations.
Points at which you are expected to compute and work out answers and write them in
your log book are marked with a pencil... .
Ill-conditioning
What are the eects of rounding errors, say, on tha accuracy of a linear simultaneous
equation of the form
Ax
=
b
?
Let's start by looking at a simple one variable problem, e.g.
ax
=
b
with errors in
a
and
b
. Dierentiating gives
ax
+
ax
=
b
or, and more usefully
¯¯¯¯
x
x
¯¯¯¯
=
¯¯¯¯
b
b
a
a
¯¯¯¯
¯¯¯¯
b
b
¯¯¯¯
+
¯¯¯¯
a
a
¯¯¯¯
This means that the
proportional errors add
.
Consider the equation of the form
Ax
=
b
,
·
1 1
0
:
9 1
:
1
¸·
x
y
¸
=
·
2
2
¸
Write down and plot the equations of the (two) straight lines which may represent each
of the two simultaneous equations in the matrix-vector equation above if
i)
= 0
1
pf3
pf4
pf5
pf8

Partial preview of the text

Download Engineering Mathematics Lab Exercise: Conditioning and Iteration and more Lecture notes Engineering Mathematics in PDF only on Docsity!

Second Year Engineering Mathematics

Laboratory

Exercise 1: Conditioning and iteration

Michaelmas Term

A: Conditioning of matrix-vector equations

The purpose of this exercise is to introduce you to the concepts of matrix and vector `norms' and the concept of ill-conditioned systems. This is shown using simple examples of sumultaneous linear equations. Points at which you are expected to compute and work out answers and write them in your log book are marked with a pencil....

Ill-conditioning

What are the e ects of rounding errors, say, on tha accuracy of a linear simultaneous equation of the form Ax = b? Let's start by looking at a simple one variable problem, e.g. ax = b with errors in a and b. Di erentiating gives ax + ax = b

or, and more usefully (^) ∣ ∣∣ ∣

x x

b b

a a

b b

a a

This means that the proportional errors add.

Consider the equation of the form Ax = b, [ 1 1 0 : 9 1 : 1

] [

x y

]

[

]

Write down and plot the equations of the (two) straight lines which may represent each of the two simultaneous equations in the matrix-vector equation above if i)  = 0

ii)  = 0: 1

What are the solutions for x; y in these two cases? Show that the general solution is

x = 1 + 5; y = 1 5 :

Explain qualitatively why this matrix-vector equation is so sensitive to small changes.

Matrix & vector norms

In the previous example we have seen how small errors in one component of a matrix equation can lead to very large errors in our solutions. We would like to quantify this. To do so we need to introduce the concept of matrix and vector norms. We will start with a vector x = (x 1 ; ::; xi ; :::; xn). You will be already familiar with the concept of the L 2 norm, which is the Euclidean distance

jjxjj 2 =

i

x i^2

We can generalise this to the Lp norm

jjxjjp =

i

jxi jp

) 1 =p

where p is normally an integer. Other commonly used norms are:

L 1 =

i

jxi j; the sum of the magnitudes

L 1 = limp!1 (jxi jp)^1 =p^ = max(jxi j); the largest element.

Matlab has a built-in function to calculate vector (and matrix) norms, it is called norm; type help norm. Use this function and vectors x = [1; 2 ; 3]T^ , y = [1; 1 ; 2]T^ to demonstrate that the L 2 , L 1 and L 1 norms all satisfy the basic requirements

jjkxjj = kjjxjj; where k is a scalar;

jjx + yjj  jjxjj + jjyjj:

Consider the simple potential divider circuit below, with a leakage resistor R 2 >> R 1. Show that the voltages voltages, currents and resistances obey the following equation: [ R 1 + R 2 R 2 R 2 R 1 + R 2

] [

I 1

I 2

]

[

V 1

V 2

]

R

V1 V

I1 I

R1 R

If V 1 = V (1 + ) and V 2 = V (1 ), show that the currents are given by

I 1 =

V

R 1 + 2R 2

I 2 =

V

R 1 + 2R 2

where

 =

R 1 + 2R 2

R 1

Calculate the condition number using the L 1 norm of the resistance matrix and the value of  for the cases R 1 = 1k and R 2 = (i) 1k , (ii) R 2 = 100k. Comment on your results.

B: Iterative solution of simultaneous equations

The purpose of this part of the exercise is to explore the use of iterative algorithms for solving simultaneous equations | you will be introduced to the \Jacobi" algorithm. This is done in the context of a (simpli ed) engineering problem: modelling an elastic surface under load.

Introductory reading

So far we have discussed the solution of the simultaneous linear equation set, and the conditions for ill-conditioning. The underlying assumption was that we would go ahead and solve the set of equations by a direct method, such as Gaussian elimination or simple matrix inversion. This requires, for large matrices, huge computational costs. Iterative Methods are useful where successive approximations generate solutions which converge on the exact solutions. They are a viable alternative to direct methods and can provide solutions of sucient accuracy with far fewer calculations. Let's have a look at a simple 1-d system to begin with, to refresh memories. Consider nding a solution to x cos(x) = 0:

We can easily formulate an iterative update equation of the form

xn = cos(xn 1 )

which will converge to the true solution (how can we be sure?). As an aside the iterative scheme xn = cos^1 (xn 1 ), which is an alternate arrangement of the original equation, will not converge (why?).

The Jacobi algorithm

Now let's have a look at the matrix case

Ax = b:

What we want is to re-organise the equation by splitting up matrix A into several compo- nents (which we will see working in detail a bit later). Consider A = D + E where D is the matrix of diagonal elements of A and matrix E consists of only the o -diagonal elements (i.e. it is the same as A but has zeroes along the diagonal),

(D + E)x = b

and hence xn = D^1 Exn 1 + D^1 b

which is the Jacobi iterative algorithm for nding solutions to x.

Lab Work

Simulating a springy surface

Copy the les springy.m and jacobi.m from /packages/demo/comp/newlab1 to a di- rectory called Lab1, for example, in your own area.

Compare the code in the le jacobi.m with your derivation in sections A and B of the preparation. Satisfy yourself that you understand the operation of the function springy and write down the role of each of its four parameters. Try it out by typing

springy(0.1, 50, 10, 3)

First the program computes an accurate solution for the deformed surface under a point load, using many iterations. (The use of many iterations, in this way, is of course impracti- cal in real applications, but is done here for tutorial purposes only.) Then (press RETURN) it computes some intermediate solutions, to show how the Jacobi algorithm converges.

Note down what happens when you vary the values of the parameter lambda that relates to the sti ness of the membrane, and m, n, that concern the detail and accuracy of the computed solution.

Using norms to look at convergence

Now you use the \absolute error" en = xn s (where s is the true solution vector of the linear equations) to investigate convergence experimentally. The 2-norm k : : : k 2 , denoted here just k : : : k for brevity, is used throughout. It is computed by the matlab function norm (see help norm and look under \vectors"). Ideally, you would like your iterative algorithm to terminate when kenk becomes smaller than some pre-speci ed value. Write a new function springynorm similar to springy which returns two arrays iter and e, each of length n+1. The array iter should contain the iteration number, and the array e the absolute error at each iteration. Some sample code is given below.

function [iter,e] = springynorm(lambda, m, n) % lambda: relative elasticity % m: number of nodes % n: number of iterations

b = (1:m+2)0; % array of 0's - downward forces b(m/2)=1; % with 2 1's in middle - vehicle wheels x = (1:m+2)0; % array of 0's - initial heights

% iterate 200 times to get "true" solution

xx = jacobi(lambda, x, b, 200);

iter = [0:n]; % iteration number 0,1,2,...n e(1) = norm(x-xx); % initial error

for k = 2:n+ x = jacobi(lambda, x, b, 1); e(k) = norm(x-xx); end

Run your new function for 30 iterations and plot the results:

[iter, Jnorms] = springynorm(0.1, 50, 30); plot(iter, Jnorms);

What is the convergence rate | the ratio ken+1k=kenk of successive values of abso- lute error | when lambda=0.1 and m=50? You will nd it more helpful to use a log-linear plot (matlab function semilogy). It may also be useful to examine the numerical values of the array Jnorms.