Docsity

Math 170A (Winter 2009) - Week 1 Study Guide - Prof. Emre Mengi, Assignments of Mathematics

Toggle sidebar
bg1
Instructor: Emre Mengi
Math 170A (Winter 2009)
Study Guide for Week 1
Before attempting the homework below please make sure that you have understood the topics listed
below. Please don’t hesitate to ask for help if any of these topics is unclear.
•The sensitivity of a problem and the derivative (if it exists) as a measure of the sensitivity
(lecture 1)
•Absolute, relative errors in numerical computation and their connection with the sensitivity
(lecture 1)
•Floating point representation (lecture 2, section 2.5 in the textbook)
•IEEE single and double floating point standards (lecture 2, section 2.5)
•Performing the four basic arithmetic operations +, −,×,/in IEEE arithmetic (lecture 2,
section 2.5)
•Floating point operation count (lecture 3 and section 1.2)
Homework 1 (due on January 16th, Friday by 3pm)
In Matlab questions (questions 3 and 4) attach the Matlab outputs to your answer.
1. Consider the function f:Rn→Rdefined as
f(x) = xTAx
where x∈Rnand Ais an n×nmatrix with real entries. It is easy to verify that this is a
(multivariate) quadratic (degree 2) polynomial of the components of x. For instance
fs x1
x2=x2
1+ 3x1x2+ 5x2
2=x1x21 2
1 5 x1
x2.
(a) Find the gradient of fs x1
x2.
(b) Suppose a numerical algorithm to compute fs(x) returns ˆ
fs(x) = fs(x+δx), i.e. the
exact value of the function evaluated at a nearby point. Find an upper bound for the
absolute error |ˆ
fs(x)−fs(x)|using the derivative from part (a) and in terms of kδxk.
(c) Repeat part (a) for the general quadratic function f(x).
(d) Repeat part (b) for f(x) instead of fs(x).
(e) A Matlab code to compute f(x) is given below. (recall that ndenotes the size of the
vector x)
pf3
pf4

Partial preview of the text

Download Math 170A (Winter 2009) - Week 1 Study Guide - Prof. Emre Mengi and more Assignments Mathematics in PDF only on Docsity!

Instructor: Emre Mengi

Math 170A (Winter 2009)

Study Guide for Week 1 Before attempting the homework below please make sure that you have understood the topics listed below. Please don’t hesitate to ask for help if any of these topics is unclear.

  • The sensitivity of a problem and the derivative (if it exists) as a measure of the sensitivity (lecture 1)
  • Absolute, relative errors in numerical computation and their connection with the sensitivity (lecture 1)
  • Floating point representation (lecture 2, section 2.5 in the textbook)
  • IEEE single and double floating point standards (lecture 2, section 2.5)
  • Performing the four basic arithmetic operations +, −, ×, / in IEEE arithmetic (lecture 2, section 2.5)
  • Floating point operation count (lecture 3 and section 1.2)

Homework 1 (due on January 16th, Friday by 3pm) In Matlab questions (questions 3 and 4) attach the Matlab outputs to your answer.

  1. Consider the function f : Rn^ → R defined as

f (x) = xT^ Ax

where x ∈ Rn^ and A is an n × n matrix with real entries. It is easy to verify that this is a (multivariate) quadratic (degree 2) polynomial of the components of x. For instance

fs

([

x 1 x 2

])

= x^21 + 3x 1 x 2 + 5x^22 =

[

x 1 x 2

]

[

] [

x 1 x 2

]

(a) Find the gradient of fs

([

x 1 x 2

])

(b) Suppose a numerical algorithm to compute fs(x) returns fˆs(x) = fs(x + δx), i.e. the exact value of the function evaluated at a nearby point. Find an upper bound for the absolute error | fˆs(x) − fs(x)| using the derivative from part (a) and in terms of ‖δx‖.

(c) Repeat part (a) for the general quadratic function f (x).

(d) Repeat part (b) for f (x) instead of fs(x).

(e) A Matlab code to compute f (x) is given below. (recall that n denotes the size of the vector x)

function f = computef(A,x)

n = length(x);

for j = 1:n Atimesx(j) = 0;

for k = 1:n Atimesx(j) = Atimesx(j) + A(j,k)*x(k); end end

f = 0; for j = 1:n f = f + Atimesx(j)*x(j); end

return;

Write down the total number of addition and multiplication operations required by this code to compute f (x) in terms of n.

  1. Let x = 2, y = 2^24 , w = −1 and z = 2−^23. In parts (b) and (c) ⊕ and ⊗ denote the addition and multiplication in IEEE single precision.

(a) Find the floating point number in IEEE single precision that is closest to and greater than x. Repeat this for y and z.

(b) Perform the following operations; (i) x ⊕ y, (ii) x ⊕ z and (iii) (x ⊕ y) ⊗ (x ⊕ z).

(c) Verify that (w ⊕ x) ⊕ z 6 = w ⊕ (x ⊕ z). This shows that the addition in IEEE floating point arithmetic is not associative.

(d) Is the addition in IEEE floating point arithmetic commutative? In other words does the equality x 1 ⊕ x 2 = x 2 ⊕ x 1 hold for any two floating point numbers x 1 , x 2 in single or double precision?

  1. Have a look at Exercise 2.5.7 in your textbook. Also please go over the lecture notes concerning double precision IEEE arithmetic. Matlab performs all of the computations below in double precision arithmetic. You should type “format long e” before running the m-files below to view the outputs in double precision. This question is a slightly modified version of Exercise 2.5.7.

(a) A Matlab m-file accuracy.m is provided on the course website and its content is given below.

function [] = accuracy3()

a = 1;

while a ~= 0 b = a; a = 0.5*a; end

b

return

Save and run this m-file. What does the value of b printed out at termination corre- spond to in IEEE double precision arithmetic?

  1. Solve Exercise 1.1.9 on page 5 in your textbook. Note that there is some crudeness in the way the running time is measured. You should not try to run the Matlab code with small n. On the other hand if you set n very large (for instance n ≥ 12000), Matlab may give an error due to the intense amount of memory required to store large matrices. In my computer I can see the expected behavior when I set n = 2500 and iterate three times (i.e. for jay = 1:3). For your computer these values may be different. For an appropriate value of n and appropriate number of iterations can you observe a quadratic running time for the matrix-vector product Ax with respect to the size of the vector x?