Deprtment of Mechncl Engneerng, Unversty of Bth Mthemtcs ME10305 Prolem sheet 11 Lest Squres Fttng of dt NOTE: If you re gettng just lttle t concerned y the length of these questons, then do hve look t the exm ppers for the lst few yers to see clerly how much wll e expected n the exm n My If you cn tckle the followng questons well, then you wll no fers t ll wth the lest squres queston n the exm The chef prolem my well e gettng your clcultor technque to e completely relle Therefore, I would suggest tht you should ttempt very quck sketch of the dt n the exm Ths wll llow you to see clerly f your computed coeffcents re resonle 1 You re gven the followng dt: x : 0 1 2 3 4 5 6 7 1 y : 00761 011015 030136 037160 05320 045020 041131 04463 042693 () Assume tht ths dt should le on strght lne through the orgn Fnd tht lne () Now ssume tht the dt should le on the strght lne y mx+c Wht s the lne? () Extend () to qudrtc curve In ll the cses determne the RMS of the lne/curve otned Whch ft s est? [Note: the detled summtons requred for ths mght e done more esly usng pckge such s Excel] ANSWER: For ll three prts of the queston we need to evlute some sums These re gven n Fgure 1 n the ccompnyng document, together wth grphs of the dt ponts nd the three ftted curves The RMS vlues re lso stted wthn ech frme, nd some comments on wht s hppenng re gven there It s generlly true tht the RMS level drops s the degree of the polynoml ncreses Qute clerly the RMS wll drop to zero once n polynoml of degree n hs een ftted to n+1 ponts (smply ecuse such polynoml hs n+1 coeffcents) But t s not usully wse to try to ft very hgh order polynoml to nosy dt The process of fttng hgh order polynoml tends to e unstle n the sense tht the overll curve otned s qute senstvely dependent on the vlues of the coeffcents Generlly 1st, 2nd or possly 3rd order polynoml s suffcent for our needs I hve lso run nother two cses n order to gve some further understndng of how the degree of excellence of the ft vres wth the numer of ponts nd the nose level These re gven n Fgures 2 nd 3 In Fgure 2 101 pont verson of the tutorl queston s gven The reducton n the RMS s not so gret n ths cse, possly due to the fct tht the nose level s oscurng the overll shpe of the grph On Fgure 3 the nose level hs een reduced to 005 from 025 Now t s cler tht the prolc ft s much etter thn the lner fts Not only does the RMS vlue tell us ths, ut the eye does t well, too
2 In ths queston we re gong to ply dfferent gme n the sense tht the dt to e ftted hs dfferent type of rndomness I would lke to see how much ccurcy one cn gn from set of dt whch hs een rounded qute severely We ll use the converson from mles to klometres for ths purpose The followng s Tle of dt whch s suject to dfferent degrees of roundng off, nmely to zero, 1, 2 nd 3 decml plces; x denotes mles nd yn denotes klometres wth n decml plces For ech of these sets of dt, ft strght lne through the orgn to determne the lest squres verson of the converson fctor etween the unts How ccurte re they? You my compre wth the exct vlue, 1609344 x : 1 2 3 4 5 6 7 9 10 y0 : 2 3 5 6 10 11 13 14 16 y1 : 16 32 4 64 0 97 113 129 145 161 y2 : 161 322 43 644 05 966 1127 127 144 1609 y3 : 1609 3219 42 6437 047 9656 11265 1275 1444 16093 If ths hs pqued your nterest, then try the sme wth the converson etween ounces nd grms, for whch 1 ounce s equl to 2349523 grms Use 16 sets of dt from 1oz to 16oz, nd use the sme numer of decml plces s n the ove mles/klometres exmple The rw dt my e found t http://stffthcuk/ensdsr/me10305ho/ounces-to-grmstxt lthough there s lso lnk to t t the unt wepge Gven tht there re 16 dt ponts, you mght e le to coerce Excel nto dong your clcultons for you ANSWER: We re fttng the slope of the lne y mx, where x mles nd y klometres The formul s,n m y,n x It shouldn t tke too long to fnd y, whle x2 35 We get the followng results: DPs y m error 0 614000 159405 0014539 1 620000 1610390 0001046 2 61950 1609299 0000045 3 619591 1609327 0000017 Qute frnkly, I m mzed tht we should get n error s smll s 1% for the zero decml plces cse As the numer of decml plces n the rw dt ncreses, there s cler trend towrds hvng gretly mproved ccurcy However, I hve to wrn you tht ths s not t ll strghtforwrd: f the numer whch s eng sought hs only few decml plces tself, then t s qute possle for the round-off error n the rw dt to e sed towrds one sde of the correct vlue In other words, errors ncurred y the roundng off mght not hve zero men nd f tht s true, then the ccurcy of ths pproch s mpred Wth regrd to the ounces/grms exmple, we get the followng Tle of results: DPs m error 0 2350267 0000744 1 234195 000132 2 2349532 0000009 3 2349521 0000002 So gn we get some pretty spectculr ccurcy, lthough there s smll errton n tht the zero-dp cse s slghtly more ccurte thn the 1-DP cse
I hve to dmt tht ths queston ws motvted y queston I sked myself s chld wth nothng much to do on cold wnter s evenng, wthout ccess to wkped nd efore clcultors could e ought I hd notced tht the converson fctor correspondng to the numers of ounces nd numers of grms ws not the sme etween 4oz sl of utter nd 12oz jr of jm Both were quoted n whole numers nd the fctors re 225 nd 2333, respectvely By ssumng tht the ounces were precse nd tht the grms hd een rounded, I tred to work out from the vrous foodstuffs n the house the rnge of possle vlues tht the converson fctor could tke Ech quoted numer of grms s equvlent to rnge of vlues whch re rounded the sme the wy, nd therefore one s le to get rnge of possle converson fctors for ech cse I eventully settled on 235, whch wsn t too d, nd whch s why I hve lwys rememered the numer 3 Suppose tht you were gven set of expermentl dt where t s suspected tht the dt should stsfy n equton of the form y +/x How could the dt e mnpulted n order to use stndrd Lest Squres theory? [Note: I cn thnk of t lest two dfferent wys of dong ths] Wht out the equton, y x+? ANSWER: The frst wy would e to multply oth sdes of the gven equton y x to get xy x+ If now we defne, Y xy nd X x, we cn do stndrd lner Lest Squres ft to Y X + to fnd nd, from whch we cn then fnd y s functon of x The second wy would e to let X x 1 nd Y y, to otn Y +X, nd hence we would fnd nd usng stndrd Lest Squres theory I wll leve t to you to decde whether these two wys would yeld the sme coeffcents The equton, y /(x+) my e rerrnged nto the form, x y, nd then we my use one of the two methods ove to fnd nd 4 In mny expermentl stutons the oservle, y, s power lw functon of the prmeter, x In other words t tkes the form, y x, where nd need to e found [For exmple, the rte of het trnsfer from hot vertcl surfce s proportonl to the 1 4 power of the temperture dfference etween the heted surfce nd the ment condtons] How would you convert ths power-lw reltonshp nto strght lne reltonshp? ANSWER: If one tkes nturl logrthms of the gven equton, then t ecomes, lny ln+lnx
It s very very lkely tht oth x nd y wll e sngle-sgned for the type of experments whch stsfy such reltonshps, such s the quoted exmple where the oth the rte of het trnsfer nd the temperture dfference re postve However, should x e negtve, then we cn lwys replce t y x x, nd use x nsted Therefore we my defne Y lny, X lnx, A ln nd B, nd use stndrd Lest Squres theory to ft Y A+BX 5 Expermentl mesurements hve een tken of z, whch s functon of oth x nd y It s suspected tht z s lner functon of x nd y, nd therefore t represents plne n 3D spce Use lest squres theory to determne the three unknown coeffcents n the followng equton for the plne, z x+y +c ANSWER: The nswer for ths queston s no more dffcult thn the dervton for fttng qudrtc lne We need to mnmse the sum of the squres of the resduls for z x+y +c: S n (z y c) 2 We need to set to zero n turn ech of the three frst prtl dervtves of S wth respect to, nd c Ths gves the followng equton, x 2 y y N y 2 y N y z y z c z
6 An osessve cyclst hs comprehensve set of dt for hs/her rde-tmes over the sme route for perod of severl yers Nturlly the cyclst s journey tmes re slower when the wether s colder, nd fster when t s wrmer The cyclst wshes to determne () wht the long term generl trend s n terms of speed, () wht sesonl effect should e expected gven the tme of yer To ths end, the cyclst proposes lest squres ft of the form, T +t+ccos(2πt)+dsn(2πt) where T s the rde-tme nd t s tme mesured n yers Develop the lest squres theory whch wll llow the cyclst to cheve hs/her twn ojectves ANSWER: The pproprte equton to solve s N t cos2πt t t 2 t cos2πt cos2πt t cos2πt cos 2 2πt N N sn2πt t sn2πt sn2πt cos2πt sn2πt T t sn2πt T t sn2πt cos2πt c T cos2πt N sn 2 2πt d T sn2πt Clerly the cyclst wll wsh to see tht s negtve to ndcte tht the journey tme s decresng overll, nd hence tht the speed s mprovng The vlues of the coeffcents, c nd d, wll llow the cyclst to determne t whch pont of the yer tht one mght expect the journey tme to e t ts gretest Gven tht, where φ s phse whch stsfes oth ccos(2πt)+dsn(2πt) c 2 +d 2 cos(2πt φ), cosφ c c2 +d 2 nd snφ d c2 +d 2, t s cler tht c 2 +d 2 wll e the expected vrton n journey tme from the men durng the yer In ddton, the vlue of t whch stsfes, 2πt φ, wll gve tht pont n the yer when the journey tme s expected to e t ts mxmum I suspect tht tht mght very well e n Jnury or Ferury 7 Let us generlze thngs lttle Suppose tht we hve to ft the followng curve to mesured dt: y f(x)+g(x), where f(x) nd g(x) re chosen functons nd nd re to e found It my help you to thnk of f(x) nd g(x) s eng 1 nd x (Q1()), or 1 nd 1/x (Q3), or cos(2πx) nd sn(2πx) (lst two components n Q6) How does one modfy lest squres theory to ths generlzton? ANSWER: Dre I sy tht we proceed s usul! Let us wrte out the sums of the squres of the resdul: ( ) 2, S y f g
where I hve used f nd g s shorthnd notton for f( ) nd g( ), respectvely We need to mnmse S wth respect to oth nd Hence, S ( N 0 f 2 ) + ( ) S ( N 0 ( )+ Rerrngng nto mtrx/vector form, we get f 2 g 2 g 2 ) f y, g y f y g y It s cler from ths result tht there s defnte pttern out how lest squres works for generl cses So f we hd to ft the followng three functons: y f(x)+g(x)+ch(x), then the pproprte scheme would e, f 2 f h g 2 g h N f h f y g h g y h 2 c h y An experment hs two mesurles, y(x) nd z(x), s the control prmeter, x, s vred Both y nd z should e lner wth dfferent slopes, ut should hve the sme ntercept on the vertcl xs Tht s, we wsh to ft the followng to the dt, where there re three constnts to fnd: y x+c, z x+c How s ths done? [Ths s smplfed verson of prolem couple of thrd yer students rought to me where they hd to ft strght lne to fve mesureles ll of whch hd the sme ntercept So ths queston sn t product of my wld mgnngs! Wht ws the nswer for ther prolem?] ANSWER: The sums of the squres of the resduls my now e wrtten n the form, [ (y S c ) 2 ( + z c ) ] 2
There re three constnts to fnd,, nd c, nd therefore we wll need to set ll three frst prtl dervtves to zero Here s the fnl nswer: x 2 0 0 Note the presence of the 2N n the mtrx x 2 2N y z c (y +z ) Note: ths queston rose from couple of thrd yer Group Busness nd Desgn students need to ft fve lnes wth common ntercept I hdn t seen such type of lest squres nlyss efore, ut the extenson to the ove theory from two to fve lnes pprently worked perfectly for ther dt If we were to wrte ther fve equtons s y (1) m (1) x + c, y (2) m (2) x + c, nd so on, then the requred mtrx vector system for the sx constnts would e: x 2 0 0 0 0 0 x 2 0 0 0 0 0 x 2 0 0 0 0 0 x 2 0 0 0 0 0 x 2 5N m (1) m (2) m (3) m (4) m (5) c y (1) y (2) y (3) y (4) y (5) 5 j1[ y (j) ] DASR 02/02/2016