全文预览

FORTRAN课程设计2014级

上传者:塑料瓶子 |  格式:doc  |  页数:14 |  大小:230KB

文档介绍
РReal x1,x2,x,f1,f2,fxРx=(x1+x2)/2.0Рfx=func(x)Рdo while(abs(fx)>1e-6)Рf1=func(x1)Рif(f1*fx<0) thenР x2=xРelseР x1=xРendifРx=(x1+x2)/2.0Рfx=func(x)РenddoРbisect=xРendРfunction func(x)Рreal xРfunc=x**3-2*x**2+7*x+4РendР2.弦截法求一元方程的根РProgram exam12-2РReal x1,x2,xРReal secant,funcРDoРPrint*,’输入x1,x2的值:’РRead*,x1,x2Р If(func(x1)*func(x2)<0.0) exitРEnddoРx=secant(x1,x2)Рprint 10,’x=’,xР10 format(a,f15.7)РEndРReal function secant(x1,x2)РReal x1,x2,x,f1,f2,fxРReal funcРx=x2-(x1+x2)/(func(x2)-func(x1))*func(x2)Рfx=func(x)Рdo while(abs(fx)>1e-6)Рf1=func(x1)Рif(f1*fx<0) thenР x2=xРelseР x1=xРendifРx=x2-(x1+x2)/(func(x2)-func(x1))*func(x2)Рfx=func(x)РenddoРsecant=xРendРreal function func(x)Рreal xРfunc=x**3-2*x**2+7*x+4РendР3.牛顿迭代法РProgram exam12-3РReal xРInteger mРPrint*,’输入初值’РRead*,xРCall newton(x)

收藏

分享

举报
下载此文档