03.03.2014 Views

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

122 CHAPTER 9. LEAST SQUARES<br />

Exercises<br />

(9.1) How do you know that the choice of constants c i in our least squares analysis actually find a<br />

minimum of equation 9.1, and not, say, a maximum?<br />

(9.2) Our “linear” least squares might be better called the “affine” least squares. In this exercise<br />

you will find the best linear function which approximates a set of data. That is, find the<br />

function f(x) = cx which is the least squares best approximant to the given data<br />

x x 0 x 1 . . . x n<br />

y y 0 y 1 . . . y n<br />

(9.3) Find the constant that best approximates, in least squares sense, the given data x, y. (Hint:<br />

you can use equation 9.2 or equation 9.3 using a single basis function g 0 (x) = 1.) Do the x i<br />

values affect your answer?<br />

(9.4) Find the function f(x) = c which best approximates, in the least squares sense, the data<br />

x 1 −2 5<br />

y 1 −2 4<br />

(9.5) Find the function ax + b that best approximates the data<br />

x 0 −1 2<br />

y 0 1 −1<br />

(9.6) Find the function ax 2 + b that best approximates the data<br />

x 0 1 2<br />

y 0.3 <strong>0.1</strong> 0.5<br />

(9.7) Find the constant c such that f(x) = ln (cx) best approximates, in the least squares sense,<br />

the given data<br />

x x 0 x 1 . . . x n<br />

y y 0 y 1 . . . y n<br />

(Hint: You cannot use basis functions and equation 9.2 to solve this. You must use the<br />

Definition 9.1.1.) The geometric mean of the numbers a 1 , a 2 , . . . , a n is defined as ( ∏ a i ) 1/n .<br />

How does your answer relate to the geometric mean?<br />

(9.8) Write code to find the function ae x + be −x that best interpolates, in the least squares sense,<br />

a set of data {(x i , y i )} i=n<br />

i=0<br />

. Your m-file should have header line like:<br />

function [a,b] = lsqrexp(xys)<br />

where xys is the (n + 1) × 2 matrix whose rows are the n + 1 tuples (x i , y i ). Use the normal<br />

equations method. This should reduce the problem to solving a 2 × 2 linear system; let<br />

octave/Matlab solve that linear system for you. (Hint: To find x such that Mx = b, use x =<br />

M \ b.)<br />

(a) What do you get when you try the following?<br />

octave:1> xs = [-1 -0.5 0 0.5 1]’;<br />

octave:2> ys = [1.194 0.430 <strong>0.1</strong>03 0.322 1.034]’;<br />

octave:3> xys = [xs ys];<br />

octave:4> [a,b] = lsqrexp(xys)<br />

(b) Try the following:<br />

octave:5> xys = xys = [-0.00001 0.3;0 0.6;0.00001 0.7];<br />

octave:6> [a,b] = lsqrexp(xys)<br />

Does something unexpected happen? Why?

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!