MATLAB改进欧拉法与四阶龙格-库塔求解一阶常微分方程_第1页
MATLAB改进欧拉法与四阶龙格-库塔求解一阶常微分方程_第2页
MATLAB改进欧拉法与四阶龙格-库塔求解一阶常微分方程_第3页
MATLAB改进欧拉法与四阶龙格-库塔求解一阶常微分方程_第4页
MATLAB改进欧拉法与四阶龙格-库塔求解一阶常微分方程_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

姓名:樊元君 学号:2012200902 日期:2012.11.06一、实验目的掌握MATLAB语言、C/C++语言编写计算程序的方法、掌握改进欧拉法与四阶龙格-库塔求解一阶常微分方程的初值问题。掌握使用MATLAB程序求解常微分方程问题的方法。、实验内容1、分别写出改进欧拉法与四阶龙格-库塔求解的算法,编写程序上机调试出结果,要求所编程序适用于任何一阶常微分方程的数值解问题,即能解决这一类问题,而不是某一个冋题。实验中以下列数据验证程序的正确性。&&-*~ /,步长h=0.252、实验注意事项yr=一科亠応—二 -必-汇的精确解为- ,通过调整步长,观察结果的精度的变化三、程序流程图:•改进欧拉格式流程图:•四阶龙格库塔流程图:开始初!|点CxO,yO);(K.Y)xl=xO+h;kl=f(xO,yO);k2=f(x0+h/2ty0+h/2*kl);k3=f(xO+h/2.y0+h/2*k2);k4=f(xl,yO+h*k3);yl=yO+h/6*(k!+2*k2+2*k3+k4).i=i+l;xO=xl;yO=y1四、源程序:•改进后欧拉格式程序源代码:function[]=GJOL(h,x0,y0,X,Y)formatlongh=input('h=');x0=input('x0=');y0=input('y0=');disp('输入的范围是:');X=input('X=');Y=input('Y=');n=round((Y-X)/h);i=1;x1=0;yp=0;yc=0;fori=1:1:nx1=x0+h;yp=yO+h*(-xO*(yOF2);%yp=yO+h*(yO-2*xO/yO);%yc=y0+h*(-x1*(ypf2);%yc=y0+h*(yp-2*x1/yp);%y1=(yp+yc)/2;x0=x1;y0=y1;y=2/(1+x0A2);%y=sqrt(1+2*x0);%fprintf('结果=%.3f,%.8f,%.8f\n',x1,y1,y);endend•四阶龙格库塔程序源代码:function[]=LGKT(h,x0,y0,X,Y)formatlongh=input('h=');x0=input('x0=');y0=input('y0=');disp('输入的范围是:');X=input('X=');Y=input('Y=');n=round((Y-X)/h);i=1;x1=0;k1=0;k2=0;k3=0;k4=0;fori=1:1:nx1=x0+h;k1=-xO*yOA2;%k1=yO-2*xO/yO;%k2=(-(x0+h/2)*(y0+h/2*k1)A2);%k2=(y0+h/2*k1)-2*(x0+h/2)/(y0+h/2*k1);%k3=(-(x0+h/2)*(y0+h/2*k2)A2);%k3=(y0+h/2*k2)-2*(x0+h/2)/(y0+h/2*k2);%k4=(-(x1)*(y0+h*k3f2);%k4=(y0+h*k3)-2*(x1)/(y0+h*k3);%y1=y0+h/6*(k1+2*k2+2*k3+k4);%y1=y0+h/6*(k1+2*k2+2*k3+k4);%x0=x1;y0=y1;y=2/(1+x0A2);%y=sqrt(1+2*x0);%fprintf('结果=%.3f,%.7f,%.7f\n',x1,y1,y);endend五、运行结果:改进欧拉格式结果:»GJOLh=0»25xO=Oy0=2输入的范国是:X=0Y=5结果刊・250,k87600000,1.88235294结果二0.500,1.59389108,1.60000000结果二0.750,L2823900S,1-28000000结果叫.000,1,00962125,L00000000结果=1.250,0.79318809,0.73048780结果“・500,0.62915123,0.61538462结果=1.750,0-50372S54,0.4923076S结果二N000,0.40966655,0.40000000结果二2.250,0*33736499,0.3298&691结果二近500,0.2823574S,0.275S6207结果W・750,0.23885673,0.23357564结果=王000,0.20429990,0.20000000结果250,0.17648S88,0.17297297结果二500,0.15383629,0.15094340结果二3.「50,61351747S,0.13278008结果二4・000,0.11964242,0.11764706结果二4・250,0.10659158,0.10-191803结果二4・500,0.09553028.0*09411765结果匕.为山(L03608040,0.O848SO64结果二弓.000,0.077948Q7J0.07692308四阶龙格库塔结果:»LGKTh=0,25i0=0y0=2输入的萄Hl是:X=0Y=5结^0,250,1.8823030,1.8823529结果=0.500,1.5998962,1.6000000结果=0.750,1.2799478,1.2800000结果=1.000,L0000271,1-0000000结果=1.250,0-7805556,0.7804378结果二1.500j0.6154594j0.6153846Slltl.750,0.4923742:,0.4923077结果=2.000,0.4000543,0.4000000结果-2.250,0.3299396,0.3298969结果=2.500,0.2758952,0.2758621结果=2.750,0.2336023,0.2335766^^=3,000,0,2000200,0,2000000结果=3・25Q卫17298S6.0,1728730结果=1500,0.1509558,0-1509434结果=3-750,0.1327899,0.1327801结果=4.000,0.1176550,0.1176471结果=4.250,0.1049245,0.1049180^^4.500,0.0941229,0,0941176结果=4.750,0.0848850,0.0848806结果=5.000,0.0769267,0.0769231

»LGKTX1xO=Oy€=2輸入的范園是;1=0Y=5结果100,1.98019?8,1,9801980结果=0.200,1.9230763,1.923076&结果刃*300,1.8348612」.8348624结果刃.400,L7241364,L724137&结果二Ck500#1.5999^84,1.6000000结果=0,60^1.4705870,1*4705802结果=0.700,1.3422312,L342281&结果-0.800fL2195122f1.2195122结果刃*900,1.1049731,L1049724结果000,1.0000012,1,0000000结果=1-100,0.9049790,0.9049774结果=1,200,0,8196739,0.8196721结果=】*300,0.7434963,0,7434944结果打*400,0.6756776,0.6756757结果=1*500,0.6153865,山6153346结果600,0.5617996,认5617978结果=1.F00?0.5141405,0.5141388结果=1.800,0,4716997,0,4716981结果=】*900,0.4338409,0,4338395结赛2・000,Q.400001%1.4000000结果=2.100,0.3696870,0-3696858结果200,0.3424668,仇3424658

结果哑.300,0.3179660,0.3179650结果二工400,0.2958589,0.2958580结果=2.500,0,2*58629,0.2758621结果弍*600,0.2577327,0.2577320结果=監700,0.2412552,0.^12545结果=2.800,0.2262449,0.2262443结果=2.900,0.2125404,0.2125399结果=J.::\LI.2000uu57':.::'U|jijij0结果-3.100^0.1835018,0.1885014结果=3.200,0.1779363,0.1779359结果=3・300,0.16S2OS9,0.1682086结果=3.400,0.1592360,0,1592357结果二3.500」.1609437,0-1509434结果=3,600,0.143266^0.1432665结果书*700,0,1361473,0,136U70结果=3.800,0.1295330,0.1295337结果=1900,0.1233808,0,1233806结果=4.000,0.1176472,0.1176471拮UM・M0.1122966,0,1122965结果X*200,0.1072963,0.1072961结果=4.300,0.1026169,0.1026167结果=4.400,0.0982320,(L0982313结果=4.500,0.09411F8?O.0941176结果二4*600,0..0902628,0,0902527结果二4.7»,0.0866177,0,0866176絃肚4・800,0.0831948,0.0831947^$=4.900,0.0799681,0.0799680结果翡.000,0.0769232,0,0769231步长分别为:0.25和0.1时,不冋结果显示验证了步长减少,对于精度的提高起到很大作用,有效数字位数明显增加。六、 实验小结:通过这次实验学习,首先第一点对改进欧拉格式和四阶龙格库塔的原理推导有了深入的理解,改进欧拉格式采用(预报+校正)模式得到较精确的原函数数值解;而四阶龙格库塔则采用多预报几个点的斜率值,采用加权平均作为平均斜率的近似值的思想达到更高精度的数值解,二阶龙格库塔的特例就是改进后的欧拉格式。七、 思考题

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论