计算物理ComputationalPhysics计算物理 (4).pdf
《计算物理ComputationalPhysics计算物理 (4).pdf》由会员分享,可在线阅读,更多相关《计算物理ComputationalPhysics计算物理 (4).pdf(38页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Isaac NewtonGottfried Leibniz Computational physiCsNumerical calculusxpositionvvelocityaaccelerationderivative derivative integralintegralNumerical calculus Numerical differentiation Numerical integration Roots of an equation Extremes of a functionNumerical differentiationTaylor expansion:To calcula
2、te f,f,f.single-variable:)(!)()(!2)()()()()(0)(0020000 xfnxxxfxxxfxxxfxfnnmultivariable:),(!2)(2),(!2)(),(!2)(),()(),()(),(),(00000020002000000000yxfyyxxyxfyyyxfxxyxfyyyxfxxyxfyxfxyyyxxyxyxffxy/2Now if we divide the space into discrete points xi with evenly spaced intervals xi+1-xi=h and label the f
3、unction at the lattice points as fi=f(xi),we obtain the simplest expression for the first-order derivative.x)f(xx)f(x)(xfii0 xilimThe first-order derivative of a single-variable function f(x)around a point xi is defined from the limit.the two-point formula for the first-order derivative)(1hOhfffiiiA
4、n improved choice:The accuracy is improved from O(h)to O(h2).3/0206/2/6/2/311321321iiiiiiiiiiiiiifhfhfffhfhfhfffhfhfhffThe three-point formula for the first-order derivative)(O2211hhfffiii)(O2311hfhffiii)()88(121)2(8)1(42112hOffffhfiiiii(1)(2)A five-point formula can be derived by including the expa
5、nsions of fi+2 and fi-2 around xi.)(O325)3(311hfhfhffiiii)(O3845)3(322hfhfhffiiiiMore pointsHigher accuracySmaller hnumber of pointsinaccuracy2O(h)3O(h2)5O(h4)SummarySimilarly,we can combine the expansions of fi2 and fi1 around xi and fi to cancel the fi,f(3)i,f(4)i,and f(5)i terms;then we havethe f
6、ive-point formula for the second-order derivative)(O163016121421122hfffffhfiiiiii )(The three-point formula for the second-order derivative 6/2/6/2/321321iiiiiiiiiifhfhfhfffhfhfhff)(O2)(O222114211hhffffhfhfffiiiiiiii Example Given f(x)=sin(x),lets calculate f(x)&f(x).Divide the region from 0 to p/2
7、to 100 equal-length intervals with 101 points i*p/200(i=0,1,2.100).For boundary points(i=0,1&99,100),we can use Lagrange interpolation to extrapolate the derivatives.Code example:3.1.Differentiation.cpp Three-point formula for fThree-point formula for fNumerical calculus Numerical differentiation Nu
8、merical integration Roots of an equation Extremes of a functionNumerical integrationDivide the region a,b into n slices,evenly spaced with an interval h.If we label the data points as xi with i=0,1,.,n,we can write the entire integral as a summation of integrals,with each over an individual slice.In
9、 general,we want to obtain the numerical value of an integral,defined in the region a,b,.)(dxxfSba 101)()(nixxbaiidxxfdxxf)()(2/)()(21011hOffhShffxxfxfniiiiiiiThe above quadrature is commonly referred as the trapezoidal rule,which has an overall accuracy up to O(h2).The simplest quadrature is obtain
10、ed if we approximate f(x)in the region xi,xi+1 linearly,that is,Trapezoidal rule We can obtain a quadrature with a higher accuracy by working on two slices together.If we apply the Lagrange interpolation to the function f(x)in the region xi-1,xi+1,we have)()()()()()()()(311111111111111hOfxxxxxxxxfxx
11、xxxxxxfxxxxxxxxxfiiiiiiiiiiiiiiiiiiiii)()4(3412/022122hOfffhSnjjjjExample Given f=sin(x),integrate f from 0 to p/2.The analytic function:-cos(x)The exact value:cos(0)-cos(p/2)=1.We can use trapezoidal rule to see how the numerical value converges to 1.Code example 3.2.Integration.cppHomework Improve
12、d integration with the three-point Lagrange interpolation implemented.Comparison with the trapezoidal rule method.)()4(3412/022122hOfffhSnjjjjNumerical calculus Numerical differentiation Numerical integration Roots of an equation Extremes of a functionRoots of an equationIf we need to find a root fo
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算物理ComputationalPhysics计算物理 4 计算 物理 ComputationalPhysics
限制150内