Course Revew Wht you hopefully hve lerned:. How to nvgte nsde MIT computer system: Athen, UNIX, emcs etc. (GCR). Generl des bout progrmmng (GCR): formultng the problem, codng n Englsh trnslton nto computer lnguge edtng complng + debuggng runnng 3. Qute bt of knowledge of C (GCR, mdterm).
Course Revew 4. MATLAB: Mtlb mtr lbortory, mtr orented. Any vrble s n rry by defult, thus lmost no declrtons. All vrbles re by defult double Hgh level lnguge: () quck nd esy codng () lots of tools (Spectrl Anlyss, Imge Processng, Sgnl Processng, Fnncl, Symbolc Mth etc.) () reltvely slow
Course Revew Trnsltor - nterpreter, reds nd eecutes lne fter lne, but All Mtlb functons re precompled. One (YOU) my dd etr functons by cretng M- fles. Lnguge structure s smlr to C: - MATLAB supports vrbles, rrys, structures, subroutnes, fles, flow of control structures -MATLAB does NOT support ponters nd does not requre vrble declrtons
Delng wth Mtrces n Mtlb Mtlb hs ll stndrd opertons & functons mplemented for mtrces (& vectors). Stndrd mth. functons of mtrces operte n rry sense (ct on ech mtr entry ndependently: ep(a), sn(a), sqrt(a) A.^0.5 >> B ep(a) B(,j) ep(a(,j)) Any mtr multplcton/dvson or rsng mtr nto some power my be both mtr nd rry operton.
Delng wth Mtrces n Mtlb A*B - mtr product of n m nd m p mtrces, but A.*B - rry (element by element) product of two n m mtrces. Bsqrt(A) Å B j sqrt(a j ), A&B - ny mtrces, but BA^0.5 Å AB*B nd A&B should be squre. Submtrces: / A(:4,3) - column vector, frst 4 elements of the 3-d column of A. A(:,3) - the 3-d column of A A(:,[ 4]) - columns of A: -d & 4-th.
Delng wth Mtrces, Emples >> C A + B; C(k,l) A(k,l) + B(k,l) >> C A*B; C(k,l) A(k,m) * B(m,l) >> C A.*B C(k,l) A(k,l)*B(k,l) >> C A^lph; >> C A.^lph; C(k,l) A(k,l)^lph Mtr multplcton, summton over the repetng nde s mpled. Element-wse (rry) operton
Course Revew I hope you ve lerned the bsc lner lgebr nd t s Mtlb mplctons:. Mtr(vector) ddton/subtrcton & multplcton. Sy, wht s the dfference between *b nd *b, where nd b re vectors?. Colon notton nd opertng wth submtrces. Remember, lots of summton, multplcton etc. loops my be elmnted by usng the colon notton (see soluton to hw8-0 for emple). 3. Bsc Mtlb synt: Gven you know C, you my fgure out mny Mtlb propertes by nlogy, but stll you re epected to hve cler de bout:
Course Revew wrtng functons n Mtlb flow of control sttements How to use desktop & mntn the workspce. How to del wth blck boes : ) help FUNCTIONNAME ) wht does the functon do? ) wht s n nd wht s out? v) how to prepre wht s n (usully vectors nd mtrces) v) delly: wht s nsde the blck bo, to predct possble problems
5. You hve lerned bout set of generl problems, whch cn be solved by progrmmng: root fndng (GCR), systems of lner equtons, systems of non-lner equtons, fttng epermentl dt.
Mtr Formulton of SLE System of lner equtons, emple: + + + n n b + +.+ n n b.. n + n + + nn n b n A - coeffcent mtr, b - lod vector.. n n n n nn... n b b... b n A b
Gussn Elmnton Emple: + y + z 0 + y + 3 z 3 - + 3 y + 0 z -4. Elmnte from eqs & 3.. Elmnte y from equton. 3. Solve eq. 3 for z nd bcksubsttute to eqs & 4. Solve eq. for y nd bcksubsttute to eq.. 5. Solve eq. for.
Gussn Elmnton (lst step) Subtrct m 3 tmes () from (3) * + () + + 3 () 3 (3) 33 3 3 3 b b b () (3) 3 () () (3) * ** The new coeffcents re gve by b (3) 33 (3) 3 b () 33 () 3 m m 3 3 b () 3 ()
Sclblty Code for Gussn elmnton contns 3 loops:. mkes n- runs to elmnte vrbles. k-th run goes through n-k rows (k,..., n-) 3. n -th row we clculte j j - m kj n-k tmes Overll bout n k (n k)(n k) opertons. Tme scles s n 3! A rther poor sclblty.
LU fctorzton. GE A ------> U (upper dgonl) GE b -------> c A LU b L c A LU L - descrbes Gussn elmnton. c L - b
Numercl Stblty Problems pper f we hve smll numbers t the dgonl of the coeffcents mtr. Soluton - pvotng. Pvotng lgorthm: Serches for the lrgest k n ech row below the current one to use for the net elmnton step, nd rerrnges the rows so tht m k s lwys less thn one.
Introducton to Dt Anlyss Rndom & Systemtc Errors How to Report nd Use Epermentl Errors Sttstcl Anlyss of Dt Sttstcs of rndom errors Error propgton, functons of mesurbles Plottng nd dsplyng the dt Fttng the dt: lner nd non-lner regresson
Sttstcl Anlyss of Rndom Errors. Men N best N Devton d Stndrd devton, σ root men squre of the mesurements N N (d ) ( ) N N
Propgton of Errors If errors re ndependent nd rndom: for the sum/dfference the errors of the ndependent tems re dded n qudrture. q + y ( ) ( ) δq δ + δ y δ+ δ y q +... + z ( u+... + w) ( )... ( ) ( )... ( ) δq δ + + δz + δu + + δw δ+... + δz+ δu+... + δw
q... z u... w Propgton of Errors Reltve error of product/quotent: δq δ δz δu δw +... + + +... + q z u w δ δz δu δw +... + + +... + z u w Reltve errors of ndependent mesurbles re dded n qudrture.
Propgton of Errors Generl cse - functon of severl vrbles: q(,...,z) δ q q q... δ z δ + + Error of power: q n δq q n δ
Gussn Dstrbuton For lrge number of mesurements nd rndom smll errors the dstrbuton of epermentl dt s Gussn: ( ) G ep, σ σ π σ P(, + d) G()d (probblty densty) P( b) G()d b G()d (normlzed) G( + d) G( d) (symmetrc wth respect to )
Lest Squres Fttng Multple mesurbles y, y,, y N, t dfferent vlues of :,,, N ; y f( ). Need to ft mesurbles y, to functon y(). The smplest cse - lner dependence: y + b. Wht re the best nd b to ft the dt?. Suggest Gussn dstrbuton for ech y, know s y.. Construct P(y, y,, y N ;,b). 3. Mmze P(y, y,, y N ;,b) wth respect to & b. 4. Fnd nd b delverng the m. vlue of P(y, y,, y N ;,b).
Probblty of sngle mesurement: Lest Squres Fttng P(y ) Probblty of set of mesurements: : ep ( ) σ y σ y N y ( + b) χ P(y, y,..., y N) : ep, N σ y χ y ( + b) ( ) σ y χ χ We look for : 0 & 0 b
Lest Squres Fttng We hve system of two lner equtons for &b wth the solutons: b y y y y, where A + b - lest squres ft to the dt, or lne of regresson of y on. ( )
Lner Lest Squres, Generl cse Our fttng functon n generl cse s: F() f () + f () + + n f n () f, f,, f n - known functons of,,,, n unknown fttng prmeters Note tht the functon tself does not hve to be lner for the problem to be lner n the fttng prmeters. There s compct wy to formulte the lest squres problem: mtr form.
Lner Lest Squres, Generl cse Let us epress the problem n mtr notton: f( ) f( )... fn ( ) ( ) ( )... ( ) Z f f fn............ f( N ) f( N )... fn( N ) Overll we hve now: y Z + e Fttng problem n mtr notton. z N T Look for mn e mn( e e) T z z T y or ( T ) T z z z y
Nonlner Regresson (Lest Squres) Wht f the fttng functon s not lner n fttng prmeters? We get nonlner equton (system of equtons). Emple: f() ( - e - ) + e y f ( ;,,..., ) + e or just y f( ) + e m Agn look for the mnmum of to the fttng prmeters. N e wth respect
Nonlner Regresson (Lest Squres) + + + + + n N n N n N N n j j j j n j j j j f f f f z f y f y D where e z D N for e f f y e f f e f y 0), (... 0), (......... 0), (... 0), ( 0), (... 0), (, form : mtr n or,,...,, 0), ( ) 0 ( 0), ( 0), ( ) 0 ( 0), ( ), (
Nonlner Regresson (Lest Squres) Lner regresson: y z + e Å z T z z T y Now, nonlner regresson: D z + e Å z T z z T D Old good lner equtons wth n plce of, D n plce of y nd z wth prtl dervtves n plce of z wth vlues of fttng functons. Besdes, n cse of lner regresson t ws enough to solve the SLE once, whle now solvng the bove system we just get the net ppromton to the best ft.
Systems of Nonlner Equtons A system of non-lner equtons: f (,,,, N )0 f (,,,, N )0 > f()0.. Strt from ntl guess [0] f N (,,,, N )0 As before epnd ech equton t the soluton wth f( )0: N N N f () f () j j j j k k j j jk j k [0] Assume s close to nd dscrd qudrtc terms f () f () + ( ) + ( ) ( ) +... N f() (j ) j j f() j :
Lnerze the system of equtons. Pck n ntl guess 0. Solve lnerzed system for correcton to the ntl guess. Use 0 + s ntl guess, nd solve the lner system gn. Repet ths procedure untl the convergence crteron s stsfed. Mtr formulton of lnerzed equtons: J( [] ) [] -f( [] ), where J Jcobn mtr, J j f /, [] [+] - []. j