You are on page 1of 7

OLLSCOIL NA hIREANN, CORCAIGH THE NATIONAL UNIVERSITY OF IRELAND, CORK

COLISTE NA hOLLSCOILE, CORCAIGH UNIVERSITY COLLEGE, CORK

SAMPLE PAPER
SUMMER EXAMINATION, 2010

BE Civil Engineering II BE Electrical Engineering II BE Energy Engineering II BE Process Engineering II

Applied Mathematics - AM2032 Numerical Methods and Programming Professor Oliver M. O Reilly Professor A. Pokrovskii Dr. J.J. Grannell

Answer one question from Section A and two questions from Section B Full marks for three questions All questions carry equal marks Calculators are allowed

Time allowed: 90 minutes

Section A
1. (a) Consider the MATLAB expression 2*3+2-72/4^2. Explain the order in which the exprerssion is evaluated. What value would MATLAB obtain for the expression? (b) Let x = [2 1 4] and y = [1 3 2]. Which of the following expressions are legitimate MATLAB expressions? i. x*y ii. x*y iii. x.*y Explain how it would evaluate each legitimate expression and what result it would obtain. (c) Write MATLAB instructions to plot the functions x = 3e t and y = 2 2e 4t in the same window using the MATLAB subplot command. Both functions should be plotted for 0 < t < 1 using 101 equally spaced points. The graphs should be side by side with the graph of x(t) on the left. (d) For each of the following, write a single MATLAB instruction to implement it: i. ii. iii. iv. v. create a 2 4 matrix A of zeros, create a 2 2 matrix B of ones, create the 2 2 identity matrix I, change A to a matrix, all of whose entries are equal to 2. Construct the matrix C from the matrices A, B and I, where 1 0 2 C= 2 1 1 0 1 2 2 1 1 1 1 2 2 1 0 1 1 2 2 0 1

(e) Write a recursive function which computes the k th term of the sequence tn = rtn 1 + a; n = 1; 2; :::; k where t0 = 0 The arguments of the function are the values of r, a and k. (f) Consider thet MATLAB instruction: mesh(X,Y,Z). What arguments does the mesh command take and what does it do? What is the dierence between the MATLAB commands mesh, surf and sur ?

2. (a) The bisection method for the solution of the nonlinear equation f (x) = 0 is applicable if the equation has a single root in an interval (a; b), if the function f is continuous on (a; b) and if the function f changes sign at the root. The method involves comparing the sign of f at one end, say a, with that at the midpoint c = (a + b)=2. If the sign of f at a is opposite to that at c the root lies between a and c. Otherwise it lies between c and b. Thus, a new interval has been found in which the root lies. The new interval is half the length of the previous interval. The mid-point of the new interval is the new estimate of the root and it lies no more than half the length of the new interval from the root. The procedure is repeated until the root is located in a su ciently small interval. Write a MATLAB function called BIS which implements the bisection method to nd an estimate of the root of the equation, assuming the above conditions are statised. The arguments of the function BIS should be the values of a and b, the accuracy to which the root is required and a function handle for f . The function BIS should return the nal estimate of the root, the error bound on this estimate and the number of iterations taken to nd the root. (b) The Heun second-order Runge-Kutta method for the solution of the initial value problem: dy = f (x; y); x > 0 dx y(0) = y0 where f is a known function of its arguments and y0 is a known number, is given by: zj+1 z0 h = zj + [f (xj ; zj ) + f (xj+1 ; zj + hf (xj ; zj ))]; j = 0; 1; 2; :::; n 2 = y0

where h is the step size and nh is the nal value of x at which the value of y is needed. Write a MATLAB function called HEUN to implement the Heun method. The arguments of HEUN should be the number of steps, n, the step size, h, the value of y0 and a handle for f . The function HEUN should return a vector consisting of the values [z0 , z1 , :::, zn ].

Section B (NOTE - there will be only FOUR questions in Section B in the examination, but I have given examples of questions on each of the six numerical topics studied)
3. (a) Give a graphical derivation of Newton method s xn+1 = xn f (xn ) ; n = 1; 2; ::: f 0 (xn )

for the numerical solution of the nonlinear equation f (x) = 0 (b) Consider the nonlinear equation x2 2=0

Apply Newton method with initial estimate x1 = 1 and compute s estimates until jxn+1 xn j < 10 2 (c) Show that the function x2 2 is strictly increasing for x > 0. Hence, show that the error in your nal estimate is less than 10 2 in magnitude.

4. (a) Let a = x1 , x2 , ... , xn 1 , xn = b be a mesh of nodes on the interval (a; b). The function f (x) is dened on the interval (a; b). Show that the polynomial of degree n 1 which has the value unity at node xi and is zero at all the other nodes is given by `n i
1

(x) =

n Yx x j=1 i j6=i

xj xj

Hence, show that the Lagrange interpolating polynomial (which equals f at the nodes) is given by: pn
1 (x)

n X i=1

f (xi )`n i

(x)

(b) Find the Lagrange interpolating polynomial of degree n = 2 which interpolates e x at the nodes 0, 0:5 and 1. Make use of your interpolating polynomial to estimate e 0:25 .

5. (a) Show that the integral

can be transformed by the linear transformation of variable x= b 2 a y+ b+a 2

f (x) dx

to an integral over the standard interval (0; 1). (b) Derive the Gaussian 2-point quadrature rule: Z 1 1 1 g(x) dx ' g( p ) + g( p ) 3 3 1 (c) Apply the Gaussian 2-point rule to nd an approximate value of the integral Z 1=2 1 dx 1 + x2 0 6. (a) A least squares approach to the approximation of the function f (x) on the interval (0; 1) by a a linear combination
n X j=1

cj

j (x)

of special functions 1 (x), 2 (x) , ..., n (x) is to choose the coe cients c0 , c1 , ..., cn so that the least square error Z 1 En = e2 dx n
0

is as small as possible, where en (x) = f (x)


n X j=1

cj

j (x)

where

Show that this approach leads to the following equations for the coe cients: n X Mij cj = bi ; i = 1; 2; :::; n
j=1

Mij bi

= =

1 i j 1

dx

dx

(b) If the special function are chosen to be monomials:


i (x)

= xi

; i = 1; 2; :::; n 1,

corresponding to approxination of f by a polynomial of degree n show that Mij bi = 1 i+j 1 Z 1 = f (x)xi


0

dx

(c) Make use of the above formulae to nd a least square approximation to sin x on (0; 1) by a polynomial of degree 1 (a straight line). 7. (a) Derive the Gauss-Seidel Method 2 i 1 X 1 4 xnew = bi aij xnew i j aii j=1

j=i+1

n X

for the solution of a system of n linear equations in n unknowns.

aij xold 5 ; i = 1; 2; :::; n j

(b) Apply the method to the numerical solution of the system: 4x1 x2 x1 + 4x2 x3 x2 + 4x3 = 3 = 2 = 3

taking (x1 , x2 , x3 ) = (0:9; 0:9; 0:9) as initial estimate. Terminate the iterations when xnew i xold < 0:05 ; i = 1; 2; 3 i

8. (a) Consider the initial value problem dy = f (x; y); x > 0 dx y(0) = y0 where f is a known function of its arguments and y0 is a known number. Derive the Crank-Nicholson method zj+1 z0 h = zj + [f (xj ; zj ) + f (xj+1 ; zj+1 )] ; j = 0; 1; 2; ::: 2 = y0

for the numerical solution of the problem. 6

(b) Apply the Crank-Nicholson method to the numerical solution of the problem dy = y; x > 0 dx y(0) = 1 Use a step size of h = 0:05 and compute z1 and z2 . (c) Give a brief explanation of how the Crank Nicholson method could be applied to nonlinear initial value problems.