Computtonl phscs Shu Dong Usng Mth nd Sene to mprove our gme
Appromton of funtons Lner nterpolton Lgrnge nterpolton Newton nterpolton Lner sstem method Lest-squres ppromton Mllkn eperment
Wht s nterpolton? Interpolton s needed when we wnt to nfer some lol nformton from set of nomplete or dsrete dt. trjetor of golf bll/footbll/mssle/...
Interpolton between two ponts Lner nterpolton = More ponts: Dret onnetons between two nerest neghbor ponts.
More smooth nterpolton Lgrnge nterpolton Let's strt from the smplest se: A A A A A A,, A,, A
Lgrnge nterpolton - Three ponts X Y O =f A A A A A A A A A
Lgrnge nterpolton - generl formul In generl, for n+ ponts: j n j j A n j j j A The prnple = j A j = =!=j A j =
How to wrte ode? A subroutne Inputs: j, j, nd Output: Algorthm n the blk bo: To lulte the oeffent A j Then we n obtn: n j A j j
Code emple double nterpolteonst double [], onst double [],onst nt n,onst double { // n+: totl ponts // [ ]: rr of // [ ]: rr of // : n double =; //= fornt j=;j<=n;j++ //Aj*j { double j=; //Aj fornt =;<=n;++ { f!=j n { Aj j*=-[]/[j]-[]; j j } } n +=j*[j]; //SumAj*j Aj } j return ; } j
Code emple equl spng ponts of os wthn [,p]:, p/,... 9p/, p, LgrngeInterpolton.pp
Results
Drwbk If one more pont s dded, ll oeffents hve to be reulted. An possble mprovement? An lterntve lgorthm: Newton nterpolton!
Newton Interpolton The ft s: =f +f +f +f 3 3 +f 4 4...+f n n polnoml funton. n order for n+ ponts Another epresson of the polnoml funton 3 Gven ponts:,,,,,... n, n Then the tsk s to lulte eh, whh onl depends on the frst + ponts. If one more pont s dded, we onl need to lulte n+.
Clulton of N = ----> : [ - ]/ - N = ---> : [ -N ]/[ - - ] N 3 3 = 3 ---> 3 : [ 3 -N 3 ]/[ 3-3 - 3 - ]... 3 3 N N N N N 3
Homework I Newton nterpolton of equl spng ponts of os wthn [,p].
One more method - self-mde The ft s: =f +f +f +f 3 3 +f 4 4...+f n n polnoml funton for n+ ponts. Then we get sstem of lner equtons nvolvng the sme set of vrbles f k k=~n. The oeffents re k k=~n. =f +f + f + 3 f 3 + 4 f 4...+ n f n
Three ponts emple Three ponts:,,,, The nterpolton funton s =f +f +f. The lner equtons re: =f +f +f =f +f +f =f +f +f f f f
Code emple vod nterpolteonst double [], onst double [],onst nt n,double f[] { // n: totl ponts // [ ]: rr of // [ ]: rr of // f[]: rr of f double [n][n]; //Mtr A fornt =;<n;++ //Aj*j { double j=; onst double =[]; fornt j=;j<n;j++ { [][j]=j; j*=; } } SolveMtr,,n,f }
Lest-squres ppromton Interpolton s mnl used to fnd the lol ppromton of gven dsrete set of dt. In mn stutons n phss, we need to know the globl behvor of set of dt n order to understnd the trend n spef mesurement or observton:----> Overll ppromton or fttng A tpl emple s polnoml ft to set of epermentl dt wth error brs.
Proess Wht do we hve? A fttng funton p vs the dt,. p s lose to but m not pss through,. The dfferenes between p nd re the error brs. The m s to redue the error brs to mnmum level b djustng the oeffents of p.
Emple: p s mth-order polnoml n>m, or the error brs n be zero m+ vrbles k k m k m p for dsrete dt ] [ ] [ m n k p
To mnmze the error brs. We get m+ lner equtons. Then solve the lner sstem for k. The smplest emple: lner fttng ] [ l k ] [ n k p
B lultng the prtl dervtve 3 n ] [ l k n n n n 3,,, where., 3 3 n n n
Johnn Crl Fredrh Guss A Germn mthemtn who ontrbuted sgnfntl to mn felds, nludng number theor, lgebr, sttsts, nlss, dfferentl geometr, geodes, geophss, mehns, eletrostts, stronom, mtr theor, nd opts. 777-855 Referred to s the Prne of Mthemtns nd gretest mthemtn sne ntqut.
Robert Andrews Mllkn In 9, Mllkn publshed hs fmous work on the ol drop eperment n Sene. Bsed on the mesurements of the hrges rred b ll the ol drops, Mllkn 868 953 onluded tht the hrge rred b n objet s multple wth sgn of Presdent of the fundmentl hrge, the hrge of n Clforn Insttute of Tehnolog eletron for negtve hrges or the Presdent of the hrge of proton for postve hrges. Amern Phsl Soet for hs work on the elementr hrge of eletrt nd on the photoeletr effet 93 Hermnn von Helmholtz ---> Albert Abrhm Mhelson st ---- > Robert Andrews Mllkn nd --->Chung-Yo Cho 赵忠尧
The Mllkn eperment Input dt Fttng equton: q k =k*q e +Q Output: Q e & Q Mllkn s orgnl ol-drop pprtus, 99-9
Code emple vod Mllknonst double k[], onst double q[],onst nt n { // n: totl ponts // k[ ]: rr of k // q[ ]: rr of q double [4]={,,,}; //oeffents fornt =;<n;++ { []+=k[]; []+=k[]*k[]; []+=q[]; [3]+=k[]*q[]; } n n n onst double q=[]*[3]-[]*[]/[]*[]-n*[]; onst double qe=[]*[]-n*[3]/[]*[]-n*[]; out<<"the elementr hrge s:\t"<<qe<<endl; } 3, 3.
..Mllkn.pp Code emple
Nonlner sstems - I For emple: the phsl behvor s n the form of p=*ep[b*], lke nuler de. If ou ft dt dretl, the huge ontrst between lrge nd smll regons wll mke the fttng nurte. An lternton s to ft ln[] nd ln[p]. ln[p]=ln[]+b*, whh s lner funton.
Nonlner sstems - II For emple: the phsl behvor s n the form of p=/-b, whh dverges t =b. An lternton s to ft nd /p. /p= / - b/, whh s lner funton.
Homework II Lest-squres ppromton for nuler de. To fnd the hlf-lfe of n unknown nuleus. tme - - -3 3-4 4-5 5-6 fsson 3 5 9 6 5 You n do t s projet!
The sore of projet Evluted bsed on the qult from the followng spets: Algorthm: orret n phss? effent n prte? fleble for other ses? Code: well orgnzed? lerl wrtten? properl ommented? robust? orret result? user-frendl? Pper: well wrtten, nludng proper fgures, tbles, & referenes f n? free from tpos nd grmmr errors?