Computatonal pyscs Sua Dong Isaac Newton Gottred Lebnz
Numercal calculus poston dervatve ntegral v velocty dervatve ntegral a acceleraton
Numercal calculus Numercal derentaton Numercal ntegraton Roots o an equaton Etremes o a uncton
Numercal derentaton Taylor epanson: To calculate ', '', '''... sngle-varable:!! n n n multvarable:,,!,,!,,!,,,,,,,, y y y y y y y y y y y y y y yy y y y /
Te rst-order dervatve o a sngle-varable uncton around a pont s dened rom te lmt. lm Δ Δ Δ Now we dvde te space nto dscrete ponts wt evenly spaced ntervals + - = and label te uncton at te lattce ponts as =, we obtan te smplest epresson or te rst-order dervatve. te two-pont ormula or te rst-order dervatve O
An mproved coce: Te accuracy s mproved rom O to O. 3 / 6 / / 6 / / 3 3 3 Te tree-pont ormula or te rst-order dervatve O O 3
8 8 8 4 O A ve-pont ormula can be derved by ncludng te epansons o + and - around. O 3 5 3 3 O 3 8 4 5 3 3
Summary number o ponts naccuracy O 3 O 5 O 4 More ponts Hger accuracy S m a l l e r
Smlarly, we can combne te epansons o ± and ± around and to cancel te ', 3, 4, and 5 terms; ten we ave te ve-pont ormula or te second-order dervatve O 6 3 6 4 Te tree-pont ormula or te second-order dervatve 6 / / 6 / / 3 3 O O 4
Eample Gven =sn, let's calculate ' & ''. Dvde te regon rom to p/ to equal-lengt ntervals wt ponts *p/ =,,... For boundary ponts =, & 99,, we can use Lagrange nterpolaton to etrapolate te dervatves.
Code eample: 3..Derentaton.cpp Tree-pont ormula or ' Tree-pont ormula or ''
Numercal calculus Numercal derentaton Numercal ntegraton Roots o an equaton Etremes o a uncton
Numercal ntegraton In general, we want to obtan te numercal value o an ntegral, dened n te regon [a, b], S b a d. Dvde te regon [a, b] nto n slces, evenly spaced wt an nterval. I we label te data ponts as wt =,,..., n, we can wrte te entre ntegral as a summaton o ntegrals, wt eac over an ndvdual slce.
n b a d d / O S n Te above quadrature s commonly reerred as te trapezodal rule, wc as an overall accuracy up to O. Te smplest quadrature s obtaned we appromate n te regon [, + ] lnearly, tat s,
Trapezodal rule
We can obtan a quadrature wt a ger accuracy by workng on two slces togeter. I we apply te Lagrange nterpolaton to te uncton n te regon [ -, + ], we ave 3 O 4 3 4 / O S n j j j j
Eample Gven =sn, ntegrate rom to p/. Te analytc uncton: -cos Te eact value: cos-cosp/=. We can use trapezodal rule to see ow te numercal value converges to.
3..Integraton.cpp Code eample
Homework Improved ntegraton wt te tree-pont Lagrange nterpolaton mplemented. Comparson wt te trapezodal rule metod. 4 3 4 / O S n j j j j
Numercal calculus Numercal derentaton Numercal ntegraton Roots o an equaton Etremes o a uncton
Roots o an equaton In pyscs, we oten encounter stuatons n wc we need to nd te possble value o tat ensures te equaton =, were can eter be an eplct or an mplct uncton o. I suc a value ests, we call t a root or zero o te equaton. I we need to nd a root or =a, ten ow? dene g=-a, and nd a root or g=.
Bsecton metod I we know tat tere s a root r n te regon [a,b] or =, we can use te bsecton metod to nd t wtn a requred accuracy. Most ntutve metod. a b < b= a = = a + b/ a < b < a < or b <? no <d? yes output!
Code Eample =sn=.5; s wtn to p/. Analytcally, we know te root s p/6. Numercally, te procedure s: snce [sn-.5]*[snp/-.5]< and [sn-.5]*[snp/4-.5]<, but [snp/-.5]*[snp/4-.5]>; ten te root must be wtn,p/4. Ten we calculate te value at p/8.... 3.3.Bsecton.cpp
Te Newton metod Ts metod s based on lnear appromaton o a smoot uncton around ts root. We can ormally epand te uncton r = n te negborood o te root r troug te Taylor epanson. r r were can be vewed as a tral value or te root o at te t step and te appromate value o te net step + can be derved.
/ =,,....
Code eample Eample: =sn=.5; g=-.5=sn-.5 g g ' -.5.5 3.4.NewtonRoot.cpp
Possble bugs I te uncton s not monotonous I ' = or very small at some ponts Works well wen te uncton s monotonous, especally wt moderate '.
Secant metod - dscrete Newton metod In many cases, especally wen as an mplct dependence on, an analytc epresson or te rst-order dervatve needed n te Newton metod may not est or may be very dcult to obtan. We ave to nd an alternatve sceme to aceve a smlar algortm. One way to do ts s to replace te analytc ' wt te two-pont ormula or te rst-order dervatve, wc gves /
Code eample Eample: =sn=.5; g=-.5=sn-.5 g -.5 p/.5 p/4 g / g g p p.5/.5.5 p 4 3.5.Secant.cpp
Numercal calculus Numercal derentaton Numercal ntegraton Roots o an equaton Etremes o a uncton
Etremes o a uncton An assocated problem to nd te root o an equaton s ndng te mama and/or mnma o a uncton. Eamples o suc stuatons n pyscs occur wen consderng te equlbrum poston o an object, te potental surace o a eld, and te optmzed structures o molecules and small clusters.
We know tat an etreme o g occurs at te pont wt dg d wc s a mnmum mamum ' = g'' s greater less tan zero. So all te root-searc scemes dscussed so ar can be generalzed ere to searc or te etremes o a sngle-varable uncton.
Eample Te onc bond lengt o te datomc molecule V r e 4p r V ep r r Na Cl were e s te carge o a proton, s te electrc permttvty o vacuum, and V and r are parameters o ts eectve nteracton. Te rst term comes rom te Coulomb nteracton between te two ons, but te second term s te result o te electron dstrbuton n te system.
Te orce: r dv r dr e 4p r V r ep r r At equlbrum, te orce between te two ons s zero. Tereore, we searc or te root o = -dv/d =.
parameters or NaCl e /4p = 4.4 AeV V =.9 3 ev r =.33 A code eample r starts rom A 3.6.NaCl.cpp
In te eample program above, te searc process s orced to move along te drecton o descendng te uncton g wen lookng or a mnmum. In oter words, or + = +, te ncrement as te sgn opposte to g'. Based on ts observaton, an update sceme can be ormulated: / ' wt 'a' beng a postve, small, and adjustable parameter. For te mnmum, ' or g'' must be postve. a g' a
Ts sceme can be generalzed to te multvarable case as a g / g were =,,..., l and g = g/, g/,..., g/ l. Note tat step ere s scaled by g and s orced to move toward te drecton o te steepest descent. Ts s wy ts metod s known as te steepest-descent metod.
Homework Searc or te mnmum o te uncton g,y=sn+y+cos+*y n te wole space