


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Instructor: Emre Mengi
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.
Homework 1 (due on January 16th, Friday by 3pm) In Matlab questions (questions 3 and 4) attach the Matlab outputs to your answer.
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.
(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?
(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?