资源描述:
《实验7 常微分方程及matlab应用》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验7常微分方程与MATLAB应用信科05-1刘武寅学号0511010110一、实验名称:常微分方程与MATLAB应用。二、实验目的:理解常微分方程单步法与多步法思想,掌握常用算法的设计,掌握用MATLAB实现的数值解法。三、实验题目:对于初值问题。四、实验要求:1、用改进的欧拉法(取h=0.05)及四阶R-K方法(取h=0.1)求解,并输出x=1+0.1i,i=0,1,……,10的数值解y。2、利用MATLAB中数值解法“ode45”与符号解法“dsolve”求解,并用图形表示各种方法的精度。五、实验内容:利用常微分解法可知方程的解为:1、利用改进欧拉法解方程:程序内容为:fun=@(x,
2、y)x^(-2)-y/x;h=0.05;X=1:h:2;Y(1)=1;fori=2:21Y(i)=Y(i-1)+h/2*(fun(X(i-1),Y(i-1))+fun(X(i),Y(i-1))+h*fun(X(i-1),Y(i-1)));end;Y运行结果为:Y=Columns1through91.00000.99890.99570.99090.98480.97780.97010.96180.9530Columns10through180.94400.93480.92540.91600.90650.89710.88760.87830.8690Columns19through210.85980
3、.85080.8418真实解的求法为:x=1:0.05:2;y=1./x.*(log(x)+1)y=Columns1through81.00000.99880.99570.99110.98530.97850.97100.9630Columns9through160.95460.94590.93700.92790.91880.90960.90040.8912Columns17through210.88210.87310.86410.85530.8466用四阶R-K算法解常微分方程的程序为:fun=@(x,y)x^(-2)-y/x;h=0.1;X=1:h:2;Y(1)=1;forn=2:11k1
4、=fun(x(n-1),Y(n-1));k2=fun(x(n-1)+h/2,Y(n-1)+h/2*k1);k3=fun(x(n-1)+h/2,Y(n-1)+h/2*k2);k4=fun(x(n-1)+h,Y(n-1)+h*k3);Y(n)=Y(n-1)+h/6*(k1+2*k2+2*k3+k4)end;Y运行后了结果为:Y=Columns1through91.00000.99570.98530.97100.95460.93700.91880.90040.8821Columns10through110.86410.8466真实解的求法为:x=1:0.1:2;y=1./x.*(log(x)+1)
5、y=Columns1through91.00000.99570.98530.97100.95460.93700.91880.90040.8821Columns10through110.86410.8466可见其精确度至少已达到0.0011、MATLAB中数值解法“ode45”为:[x1,y1]=ode45(@(x,y)x^(-2)-y/x,[1,2],y0);符号解法“dsolve”求解为:dsolve('Dy=x^(-2)-y/x','y(1)=1','x')ans=(log(x)+1)/x画出两种算法的图形位:[x1,y1]=ode45(@(x,y)x^(-2)-y/x,[1,2],1)
6、;fplot('(log(x)+1)/x',[1,2]);holdon,plot(x1,y1,'ro');数值算法同解析算法几乎完全吻合。