欢迎来到三一文库! | 帮助中心 三一文库31doc.com 一个上传文档投稿赚钱的网站
三一文库
全部分类
  • 研究报告>
  • 工作总结>
  • 合同范本>
  • 心得体会>
  • 工作报告>
  • 党团相关>
  • 幼儿/小学教育>
  • 高等教育>
  • 经济/贸易/财会>
  • 建筑/环境>
  • 金融/证券>
  • 医学/心理学>
  • ImageVerifierCode 换一换
    首页 三一文库 > 资源分类 > PPT文档下载  

    常用算法的程序设计举例.ppt

    • 资源ID:3467513       资源大小:760.52KB        全文页数:21页
    • 资源格式: PPT        下载积分:6
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录   微博登录  
    二维码
    微信扫一扫登录
    下载资源需要6
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    常用算法的程序设计举例.ppt

    第八章第八章 常用算法的程序设计举例常用算法的程序设计举例 第一章第一章 算法算法 第二章第二章 计算机和计算机程序计算机和计算机程序 第四章第四章 逻辑运算和选择结构逻辑运算和选择结构 第五章第五章 循环结构的实现循环结构的实现 第六章第六章 FortranFortran的数据结构的数据结构 第七章第七章 数据的输入、输出数据的输入、输出 第三章第三章 FortranFortran语言程序设计初步语言程序设计初步 Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 1 一、数值积分 几何意义: Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 2 近似求小曲边梯形面积的方法: (1)用小矩形代替小曲边梯形; (2)用小梯形代替小曲边梯形; (3)在小区间范围内,用一条抛物线代替该区间内的f(x)。Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 3 read(*,*) a,b,n x=a h=(b-a)/n f0=exp(x) s=0.0 do 10 i=1,n si=f0*h s=s+si x=x+h f0=exp(x) 10continue write(*,100) a,b,n write(*,200) s 100format(1x,'a=',f10.3,3x,'b=', $ f10.3,3x,'n=',i4) 200format(1x,'s=',f15.8) end 1. 矩形法 Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 4 read(*,*) a,b,n x=a h=(b-a)/n s=0.0 do 10 i=1,n si=(sin(x+(i-1)*h)+ $ sin(x+i*h)*h/2.0 s=s+si 10continue write(*,100) a,b,n write(*,200) s 100format(1x,'a=',f10.3,3x, $ 'b=',f10.3,3x,'n=',i4) 200format(1x,'s=',f15.8) end 2. 梯形法 Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 5 其他几种 程序变形 . . . f1=sin(a) . . . do 10 i=1,n f2=sin(a+i*h) si=(f1+f2)*h/2.0 s=s+si f1=f2 10continue . . . . . . x2=a . . . do 10 i=1,n x1=x2 x2=x2+h si=(sin(x1)+ $ sin(x2)*h/2.0 s=s+si 10continue . . . . . . f0=sin(a) h=(b-a)/n s=f0 do 10 i=1,n f=sin(a+i*h) s=s+2.0*f 10continue s=(s-sin(b)*h/2.0 . . . Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 6 3. Sinpson法 取a,b中点c(a+b)/2,0),通过 f(a),f(b),f(c)三点可作唯一一条抛物 线f1(x)。 根据抛物线定积分求值公式,有: 如果将(a,b)分成两个小区间(a,c) 和(c,b): Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 7 如果将(a,b)分成四个小区间: 如果将(a,b)分成n个小区间: Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 8 read(*,*) a,b,n h=(b-a)/(2.0*n) s=0.0 fa=1.0/(1.0+a) fb=1.0/(1.0+b) x=a+h f2=0.0 f4=1.0/(1.0+x) do 10 i=1,n-1 x=x+h f2=f2+1.0/(1.0+x) x=x+h f4=f4+1.0/(1.0+x) 10continue s=h/3.0*(fa+fb+4.0*f4+2.0*f2) write(*,100) a,b,n write(*,150) s 100format(1x,'a=',f8.2,2x,'b=',f8.2, $ 2x,'n=',i4) 150format(1x,'s=',f16.7) end 三种求定积分的方法中,矩形法的误差较大 ,梯形法次之,辛普生法最好。 Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 9 二、解一元方程(解非线性函数) 1. 直接迭代法 read(*,*) x,m do 10 i=1,m x1=(-x*3-2.0*x*x-2.0)/2.0 write(*,100) i,x1 if(abs(x-x1).gt.1e-6) then x=x1 else stop end if 10continue write(*,200) m 100format(1x,'i=',i3,5x,'x1=',f15.7) 200format(1x,'computation has not', $ 'converged after',i4,'iteration') end 因有收敛问题,要 设最大循环次数。 Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 10 有的g(x)是收敛的,而有的g(x)是不收敛的。 同一个g(x),对某些x0是收敛的,对有的x0则是不 收敛的。 如果g(x)具有一阶导数连续,且对于所有的x ,若|g(x)|q1(q为一个定数),那么x=g(x)对于 任意的x0均收敛,且q愈小,收敛速度愈快。如果 不满足对所有的x存在|g(x)|q1 ,则可能对有的 x0收敛,对有的x0不收敛。 因此要恰当的选择g(x)形式和初值x0。 Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 11 2. 牛顿迭代法 read(*,*) x n=1 10 x1=x f=x1*3-2.0*x1*2+4.0*x1+1.0 f1=3.0*x1*2-4.0*x1+4.0 x=x1-f/f1 write(*,100) n,x1,x n=n+1 if(abs(x-x1).gt.1e-6) goto 10 100format(1x,'n=',i3,3x,'x1=',f15.7, $ 3x,'x=',f15.7) end Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 12 3. 二分法 5read(*,*) x1,x2 f1=x1*3-6.0*x1-1.0 f2=x2*3-6.0*x2-1.0 if(sign(f1,f2).eq.f1) goto 5 10x=(x1+x2)/2.0 f=x*3-6.0*x-1.0 if(sign(f,f1).eq.f) then x1=x f1=f else x2=x f2=f end if if(abs(x1-x2).gt.1e-5).and. $ abs(f).gt.1e-6) goto 10 if(abs(f).gt.1e-6) x=(x1+x2)/2.0 write(*,100) x 100format(1x,'x=',f15.7) end Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 13 4. 弦截法(割线法) 5read(*,*) x1,x2 f1=x1*3-2.0*x1*2+7.0*x1+4.0 f2=x2*3-2.0*x2*2+7.0*x2+4.0 if(sign(f1,f2).eq.f1) goto 5 f=1.0 20if(abs(x1-x2).gt.1e-5).and. $ abs(f).gt.1e-6) then x=x2-(x2-x1)/(f2-f1)*f2 f=x*3-2.0*x*2+7.0*x+4.0 if(sign(f,f1).eq.f) then x1=x f1=f else x2=x f2=f end if goto 20 end if if(abs(f).gt.1e-6) x=(x1+x2)/2.0 write(*,100) x 100format(1x,'x=',f15.7) end Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 14 以上方法都是近似求根,得到不是准确值而是近 似值。但只要给定的误差足够小,就可以认为它们之 间足够近似。 事实上,只有少数的方程才能用解析的方法求出 准确的根值。 计算机可以解任何有实根的一元方程,它采用的 基本方法就是迭代,经过多次迭代,使近似根逐渐趋 近于真实根。迭代可以用循环实现,正好充分发挥计 算机快速运算的特点。 Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 15 三、求函数极值 Fibonacci搜索算法,或0.618法,或黄金值搜索法。 Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 16 f1=x1*x1-4.0*x1+5.0 f2=x2*x2-4.0*x2+5.0 if(f1.gt.f2) then f=f2 x=x2 else f=f1 x=x1 end if write(*,204) x,f 200format(12x,'x1',14x,'f1', $ 13x,'x2',13x,'f2'/) 202format(1x,4f15.7) 204format('0','x=',f10.6,5x, $ 'f(x)=',f10.7) end real low,high,x1,x2 read(*,*) low,high write(*,200) x1=low+0.618*(high-low) x2=high-0.618*(high-low) 10if(high-low.gt.1e-4) then f1=x1*x1-4.0*x1+5.0 f2=x2*x2-4.0*x2+5.0 write(*,202) x1,f1,x2,f2 if(f1.gt.f2) then high=x1 x1=x2 x2=high-0.618*(high-low) else low=x2 x2=x1 x1=low+0.618*(high-low) end if goto 10 end if Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 17 五、计算机模拟 计算机模拟(Computer Simulation),又称“ 仿真”:用计算机模仿实物系统进行测试,从测试 的结果获得期望的资料。 根据模拟对象的不同特点,可分为: 确定性模拟(Deterministic Mode); 随机性模拟(Stochastic Mode) 。 Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 18 小球以10m/s沿 45°斜抛,落地反 弹方向同前,速度 减小10%,求前三 次周期轨迹。 Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 19 if(abs(y).gt.0.001) then t=t-dt dt=0.1*dt t=t+dt x=v*t+x0 y=v*t-0.5*g*t*2 else write(*,100) t,x,y flag=.false. end if end if goto 5 end if v=0.9*v t=0.0 x0=x write(*,*) 10continue 100format(1x,'t=',f8.4,3x,'x=', $ f12.6,3x,'y=',f12.6) end logical flag parameter (g=9.8) read(*,*) v0,d t=0.0 x0=0.0 v=v0*cos(3.1415926/4.0) do 10 i=1,3 dt=d flag=.true. x=v*t+x0 y=v*t-0.5*g*t*2 5 if(flag) then if(y.ge.0.0) then if(dt.ge.d) $ write(*,100) t,x,y t=t+dt x=v*t+x0 y=v*t-0.5*g*t*2 else Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 20 上机目的: 1. 掌握数值积分的矩形法、梯形法和Simpson法; 2. 掌握求解一元方程的迭代法、牛顿迭代法、 二分法和弦截法; 3. 掌握计算机模拟的一般方法。 上机内容: 1. 调试课本中的所有程序; 2. 习题第5、10题。 Evaluation only.Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.Copyright 2004-2011 Aspose Pty Ltd. 21

    注意事项

    本文(常用算法的程序设计举例.ppt)为本站会员(本田雅阁)主动上传,三一文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    经营许可证编号:宁ICP备18001539号-1

    三一文库
    收起
    展开