Prof. W. Gander Masaryk University Fall 2014 Least Squares 1. Determine the parameters a and b such that the function f(x) = aebx fits the following data x 30.0 64.5 74.5 86.7 94.5 98.9 y 4 18 29 51 73 90 Hint: If you fit log f(x) the problem becomes very easy! Solution: Taking the logarithm of the function we get ln y = ln a + bx. With the unknown c = ln a the least squares problem becomes         1 30.0 1 64.5 1 74.5 1 86.7 1 94.5 1 98.9         c b ≈         ln 4 ln 18 ln 29 ln 51 ln 73 ln 90         . x=[30.0 , 64.5 , 74.5 , 86.7 , 94.5 , 98.9]’; y=[ 4 , 18 , 29 , 51 , 73 , 90]’; A = [ones(size(x)), x] b=log(y); p = A\b a=exp(p(1)) b=p(2) The solution is b = 0.04524310648 and c = 0.00789262406 ⇒ a = 1.00792752. 2. Consider the plane in R3 given by the equation x1 + x2 + x3 = 0. Construct a matrix P which projects a given point on this plane. Hint: consider first the orthogonal complement of the plane. Solution: The normal of the plane is n =   1 1 1   and the orthogonal complement is therefore Ax =   1 1 1   x. Because R3 = R(A) ⊕ N(A ) we have to compute the projector PN(A ) = I − AA+ . A+ = (A A)−1 A = 1 3 (1, 1, 1) ⇒ P = I − AA+ = I − 1 3   1 1 1 1 1 1 1 1 1   = 1 3   2 −1 −1 −1 2 −1 −1 −1 2   . 3. Given the matrix A =     1 2 6 1 3 7 1 4 8 1 5 9     Compute a Householder matrix P such that PA =     σ x x 0 x x 0 x x 0 x x     It is sufficient to determine σ and the Householder-vector u. Solution: P = I − uu with u 2 = √ 2. u = x − σe1 x 2(|x1| + x 2) , x =     1 1 1 1     , σ = − x 2 = −2 (avoid cancellation) Thus u = 1 √ 6     3 1 1 1     , Px = x − u(u x) =     1 1 1 1     − 1 √ 6     3 1 1 1     6 √ 6 =     −2 0 0 0     4. Consider the plane in R3 given by the equation 2x1 − 2x3 = 0. Construct a matrix P ∈ R3×3 which reflects a given point at this plane (computes the mirror image). Solution: The normal vector of the plane is u =   1 0 −1   Since u 2 = √ 2 the solution is given by the Householder matrix P = I − uu = I −   1 0 −1 0 0 0 −1 0 1   =   0 0 1 0 1 0 1 0 0   . 5. Let the measured points (tk, yk) for i = k, . . . , m be given. We want to fit the function f(a, b) = aebt such that m k=1 aebtk − yk 2 −→ min using the Gauss-Newton method. Write up the system of equations for the first iteration step. Solution: We want to solve the nonlinear least squares problem f(x) ≈ 0 where fi(x) = x1ex2tk − yk, k = 1, . . . , m For Gauss-Newton we expand f(x + h) ≈ f(x) + J h with the Jacobian J =    ... ... ∂fi/∂x1 ∂fi/∂x2 ... ...    =    ... ... ex2tk x1tkex2tk ... ...    . The system of equations for the correction h is a linear least squares problem    ex2t1 x1t1ex2t1 ... ... ex2tm x1tmex2tm    h1 h2 ≈ −    x1ex2t1 − y1 ... x1ex2tm − ym   