Docsity

Numerical Computing S’09 - HW-3 Solutions: Fixed Point Iteration & Gaussian Elimination - , Assignments of Computer Science

Toggle sidebar
bg1
Numerical Computing S’09 MATH/CSCI 4800-01
Homework-3 Solutions
1. (a) What is meant by a fixed point of a function g(x)?
(b) How is the problem of finding a fixed point of g(x) related to the problem of finding a zero of
another function f(x)?
(c) Suppose that we wish to develop an iterative scheme to compute the square root of a given positive
number αby solving the equation f(x) = x2−α= 0.Let the iteration be a fixed point iteration
applied to a suitably chosen function g(x).Let α= 5,and consider the following choices for g:
i.
g1(x) = x+5−x2
2.
ii.
g2(x) = 1 + x−x2
5.
For each of these choices do the following.
i. Check that the fixed-point problem for g(x) is equivalent to the problem of solving f(x)=0.
ii. Determine if the corresponding fiixed-point iteration scheme is locally convergent to √5.
What g(x) corresponds to Newton’s method for this problem?
(a) x=αis a fixed point of g(x) if g(α) = α.
(b) The problem f(x) = 0 is related to the problem g(x) = xif, given f(x), g(x) is chosen so that
the two problems have the same solution. For example, g(x) = f(x) + xensures that if x=α
solves f(x) = 0,it also solves g(x) = x.
(c) i. Since g1(√5) = √5,the problem g1(x) = xis equivalent to f(x) = 0.
g0
1(x)=1−x, |g0
1(√5)|=|1−√5|>1.
The condition for local convergence of the fixed-point iteration is not met.
ii. Since g2(√5) = √5,the problem g2(x) = xis equivalent to f(x) = 0.
g0
2(x) = 1 −2x
5, g0
2(√5) =
1−2
√5
<1.
The fixed-point iteration converges locally.
The g(x) corresponding to Newton’s method is given by
g(x) = x−f(x)
f0(x)=x−x2−5
2x=x
2+5
2x.
2. Text: Section 1.3, Page 45, Problem 2(c). This problem requires you to first select an appropriate
g(x).Many choices are possible; justify yours.
We have f(x) = ln x+x2−3.Perhaps the simplest choice is
g(x) = f(x) + x= ln x+x2+x−3.
We know that f(1) = −2 and f(2) = ln 2 + 1 >0,so that the root of fand hence the fixed point
of gis in the bracket [1,2].We note that
g0(x) = 1
x+ 2x+ 1 >1 in the bracket [1,2].
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Numerical Computing S’09 - HW-3 Solutions: Fixed Point Iteration & Gaussian Elimination - and more Assignments Computer Science in PDF only on Docsity!

Numerical Computing S’09 MATH/CSCI 4800- Homework-3 Solutions

  1. (a) What is meant by a fixed point of a function g(x)? (b) How is the problem of finding a fixed point of g(x) related to the problem of finding a zero of another function f (x)? (c) Suppose that we wish to develop an iterative scheme to compute the square root of a given positive number α by solving the equation f (x) = x^2 − α = 0. Let the iteration be a fixed point iteration applied to a suitably chosen function g(x). Let α = 5, and consider the following choices for g : i. g 1 (x) = x +

5 − x^2 2

ii. g 2 (x) = 1 + x − x^2 5

For each of these choices do the following. i. Check that the fixed-point problem for g(x) is equivalent to the problem of solving f (x) = 0. ii. Determine if the corresponding fiixed-point iteration scheme is locally convergent to

What g(x) corresponds to Newton’s method for this problem?

(a) x = α is a fixed point of g(x) if g(α) = α. (b) The problem f (x) = 0 is related to the problem g(x) = x if, given f (x), g(x) is chosen so that the two problems have the same solution. For example, g(x) = f (x) + x ensures that if x = α solves f (x) = 0, it also solves g(x) = x. (c) i. Since g 1 (

5 , the problem g 1 (x) = x is equivalent to f (x) = 0.

g′ 1 (x) = 1 − x, |g 1 ′(

The condition for local convergence of the fixed-point iteration is not met. ii. Since g 2 (

5 , the problem g 2 (x) = x is equivalent to f (x) = 0.

g 2 ′(x) = 1 − 2 x 5

, g 2 ′(

∣^1 −^

∣ <^1.

The fixed-point iteration converges locally.

The g(x) corresponding to Newton’s method is given by

g(x) = x −

f (x) f ′(x)

= x −

x^2 − 5 2 x

x 2

2 x

  1. Text: Section 1.3, Page 45, Problem 2(c). This problem requires you to first select an appropriate g(x). Many choices are possible; justify yours. We have f (x) = ln x + x^2 − 3. Perhaps the simplest choice is

g(x) = f (x) + x = ln x + x^2 + x − 3.

We know that f (1) = −2 and f (2) = ln 2 + 1 > 0 , so that the root of f and hence the fixed point of g is in the bracket [1, 2]. We note that

g′(x) =

x

  • 2x + 1 > 1 in the bracket [1, 2].

Therefore this choice will not guarantee a convergent fixed-point iteration. Let us try

g(x) = (3 − ln x)^1 /^2.

The derivative g′(x) =

2 x(3 − ln x)^1 /^2 does satisfy |g′(x)| < 1 in the bracket [1, 2] and we expect the fixed-point iteration to converge. The attached Matlab Log provides confirmation and computes the fixed point to the desired accuracy.

  1. Indicate whether the following statements are true or false; some may require going back and refreshing some basic concepts from linear algebra. Justify your answers with suitable explanation. (The matrix A is assumed to be square in all cases.)

(a) If the rows of a square matrix are linearly dependent, then so are the columns. (b) For nonsingular A the number of solutions to the system Ax = b depends upon b. (c) If A is singular, then the system Ax = b has no solutions for any b. (d) The system Ax = b may have exactly two distinct solutions. (e) Naive Gaussian elimination (no pivoting) for the system Ax = b fails only when A is singular.

(a) True. Consider, for example, a 3 × 3 matrix. If the rows are dependent, then row operations can be used to render one of the rows with zeros in all locations. The 3 columns then only have at most 2 nonzero elements each. They can therefore be considered as 2-dimensional vectors, and must be linearly dependent, as more than n vectors in an n -dimensional space are necessarily linearly dependent. (b) False. A nonsingular matrix has only one solution for any b. (c) True in general but false if A and the augmented matrix A|b have the same rank, in which case there is an infinity of solutions. (d) False. The number of solutions can only be none, one or infinity. (e) False. Even in a nonsingular matrix, naive Gaussian elimination can encounter a zero pivot.

  1. In the class we developed a pseudocode for the solution of an upper triangular system Ux = c by backward substitution. The corresponding code segment also appears in the file GaussNaive.m available on line. Write an analogous Matlab code in the form of an m-file for the solution of the lower triangular system Lx = b of order n. Apply it to solve a lower triangular system of your choice. Be sure that L is of order no less than five, and once you have chosen L, select b so that all elements in the exact solution vector x are unity. Print out L, b, and the exact and computed solution vectors. Does your code give the correct answer? See attached Matlab Log. The code gives an answer correct to 14 digits for the particular choice of the matrix L. This loss is explained by the condition number of the matrix being approximately 8 × 102.
  2. Consider the linear system Ax = b of order n where the elements of A and b are given by

ai,j = (i + 1)(j−1), bi =

(i + 1)n^ − 1 i

(The above choice of b ensures that all elements in the exact solution are unity.) Write a Matlab program GaussMain.m which calls the program GaussNaive.m, available on line, to solve the above system for n = 12, 13 and 14. For each choice of n, print out the matrices A and b, the computed solution x, the residual r = b − Ax, and kappa, the condition number of A. (The Matlab command for computing the condition number of A is cond(A).) You may need to modify GaussNaive.m so that it does not print out any other quantities. Comment on, and offer explanation for, the behavior that you observe.

MATLAB LOG, Problem 2

% Script File fixed_1.m

% Performs fixed point iteration

% g = function being iterated

% supplied as inline function

clc

maxit=15; % max iterations allowed

g=inline('(3-log(x)).^(1/2)');

r = 1; % initial guess

k = 1; % initialize iteration counter

while k< maxit

k=k+1;

r1=g(r);

r=r1;

fprintf('\n k = %i x = %20.15e \n',k,r);

end

NUMERICAL OUTPUT

k = 2 x = 1.732050807568877e+

k = 3 x = 1.565469212621553e+

k = 4 x = 1.597439953354188e+

k = 5 x = 1.591099519615788e+

k = 6 x = 1.592348800039719e+

k = 7 x = 1.592102333731531e+

k = 8 x = 1.592150945941232e+

k = 9 x = 1.592141357349521e+

k = 10 x = 1.592143248647758e+

k = 11 x = 1.592142875598611e+

k = 12 x = 1.592142949180667e+

k = 13 x = 1.592142934666978e+

% Before computing the solution the script performs a check

% to make sure that the matrix L is square. If not, an

% error message is displayed and the program terminated. It

% also makes sure that the size of b is consistent with that

% of L.

format long e

[N,M]=size(L); % the number of rows and columns in L

[P,Q]=size(b); % the number of rows and columns in b

if N ~=M, error('Matrix L is not square'); end

if N ~=P, error('L and b do not have the same number of rows');

end

% Forward substitution to solve Lx = b

x=zeros(N,1); % Initialize solution vector

x(1)=b(1)/L(1,1); % Compute x(1)

for i=2:N % forward substitution loop

s=b(i);

for j = 1:i-

s=s-L(i,j)*x(j);

end

x(i)=s/L(i,i);

end

Numerical Output

Matrix L

Columns 1 through 2

7.942845406839070e-01 2.629712845401443e-

3.112150420448049e-01 6.540790984767823e-

5.285331355062127e-01 6.892145031400078e-

1.656487294997809e-01 7.481515928237095e-

Columns 3 through 4

9.133373615016696e-01 7.817552875318368e-

1.523780189692230e-01 4.426782697754463e-

Column 5

8.173032206534330e-

Matrix b

1.621823081932428e-

1.057255825224051e+

1.194271109238406e+

2.209260528901074e+

2.326159831721593e+

Solution

1.000000000000000e+

1.000000000000000e+

9.999999999999986e-

1.000000000000016e+

9.999999999999913e-

The solution is correct, but 2 significant digits appear to have

been lost. Matlab finds that

cond(L) = 8.339468509296124e+

which explains the loss of accuracy.

Results may be inaccurate. RCOND = 5.352005e-18.

> In cond at 48

In MainGauss at 19

exact solution

computed solution

error

residual

condition number = 1.775141e+

Solution for n= 13

Warning: Matrix is close to singular or badly scaled.

Results may be inaccurate. RCOND = 7.638818e-20.

> In cond at 48

In MainGauss at 19

exact solution

computed solution

exact solution

  • k = 14 x = 1.592142937529730e+
  • k = 15 x = 1.592142936965066e+
  • 2.537537943766006e+ computed solution
  • -5.376651732077721e+
  • 5.551258883524076e+
  • -3.094505399751915e+
  • 1.333480350090902e+
  • -2.322759951487266e+
  • 1.643920206299380e+
  • 9.089265342822078e-
  • 1.009417523337632e+
  • 9.992957285971555e-
  • 1.000037073230854e+
  • 9.999986975510805e-
  • 1.000000027400743e+
  • 9.999999997390405e-
  • 2.437537943766006e+ error
  • -5.476651732077721e+
  • 5.451258883524076e+
  • -3.194505399751915e+
  • 1.233480350090902e+
  • -3.322759951487266e+
  • 6.439202062993798e-
  • -9.107346571779218e-
  • 9.417523337631684e-
  • -7.042714028444585e-
  • 3.707323085389014e-
  • -1.302448919493493e-

2.740074345197741e-

-2.609594762503775e-

residual

condition number = 9.711782e+