{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ps4sol

ps4sol - 18.02 Fall 2008 Problem Set 4 Part B Solutions 1 a...

This preview shows pages 1–2. Sign up to view the full content.

18.02 Fall 2008 – Problem Set 4, Part B Solutions 1. a) LS (4) translates into braceleftBigg ( x · x ) a + ( x · u ) b = ( x · y ) ( x · u ) a + ( u · u ) b = ( y · u ) or equivalently A z = r , with A = bracketleftbigg x x x u x u u u bracketrightbigg , z = bracketleftbigg a b bracketrightbigg , r = bracketleftbigg x y y u bracketrightbigg In Matlab notation: A=[x*x’ x*u’; x*u’ u*u’] , and r=[x*y’; y*u’] (or even shorter: A=[x;u]*[x’ u’] , r=[x;u]*y’ ) c) Matlab input and output (condensed for brevity) >> x = [1:1:7]; y = [0.25 1 2.1 4.7 9.8 18.7 48.1]; u = [1 1 1 1 1 1 1]; >> A = [x*x’ x*u’; x*u’ u*u’]; r = [x*y’; y*u’]; z = inv(A)*r z = 6.6661 -14.5714 (the best fit is: y = 6.666 x - 14.571) >> v = z’*[x;u] v = -7.9054 -1.2393 5.4268 12.0929 18.7589 25.4250 32.0911 (predicted) >> y - v 8.1554 2.2393 -3.3268 -7.3929 -8.9589 -6.7250 16.0089 (differences) a = 6 . 666, b = 14 . 571, and the largest error is about 16 (for the last data point). d) Matlab input and output: (note A remains the same) >> lny = log(y); r1 = [x*lny’; lny*u’]; z1 = inv(A)*r1 z1 = 0.8277 -1.8841 (the best fit is: ln(y) = 0.8277 x - 1.8841) >> v1 = exp(z1’*[x;u]) v1 = 0.3477 0.7956 1.8204 4.1652 9.5305 21.8066 49.8958 (predicted) >> y - v1 -0.0977 0.2044 0.2796 0.5348 0.2695 -3.1066 -1.7958 (differences) a 1 = 0 . 828, b 1 = 1 . 884, and the largest error is about 3.1 (for the sixth data point).

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 2

ps4sol - 18.02 Fall 2008 Problem Set 4 Part B Solutions 1 a...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online