15074115 薛海鹏 exercise -13 - 计算数学达人 - 专,学者,数值代数,微分方程数值解
现在时间是:
当前位置:首 页 >> 数值分析(英)>> 教学区>> 文章列表

15074115 薛海鹏 exercise -13

作者:薛海鹏   发布时间:2017-06-13 21:15:16   浏览次数:54

 6.1 Exercises

3.Use separation of variables to find solutions of the IVP given by y(0)=1 and the following differential equations:

(a) y'=t   (d)y'=5t^4y

Answer:

(a) y'=t

dy/dt=t

dy=tdt

y=(t^2/2)+c

y(0)=1,so c=1;

so,y=1+t^2/2


(b)y'=5t^4y

dy/dt=5t^4y

dy/y=5t^4dt

Iny=t^5

y=e^(t^5)+c

y(0)=1,so c=0

so y=e^(t^5)


6.1 Computer Problems

2.Plot the Euler's Method approximate solutions for the IVPs in Exercises 3 on [0,1] for step sizes h=0.1,0.05,and 0.025,along with the exact solution.

Answer:

Code:

function [t,y]=euler(inter,y0,n)

t(1)=inter(1); y(1)=y0;

h=(inter(2)-inter(1))/n;

for i=1:n

    t(i+1)=t(i)+h;

    y(i+1)=eulerstep(t(i),y(i),h);

end

plot(t,y)

function y=eulerstep(t,y,h)

%one step of Euler's Method

%Input:current time t,current value y,stepsize h

%Output:approximate solution value at time t+h

y=y+h*ydot(t,y);

function z=ydot(t,y)

z=t;

z=5*t^4*y;


Result:

(a)

>> [t,y]=euler([0,1],1,10)


t =


  Columns 1 through 7


         0    0.1000    0.2000    0.3000    0.4000    0.5000    0.6000


  Columns 8 through 11


    0.7000    0.8000    0.9000    1.0000



y =


  Columns 1 through 7


    1.0000    1.0000    1.0001    1.0009    1.0049    1.0178    1.0496


  Columns 8 through 11


    1.1176    1.2517    1.5081    2.0028


>> [t,y]=euler([0,1],1,20)


t =


  Columns 1 through 7


         0    0.0500    0.1000    0.1500    0.2000    0.2500    0.3000


  Columns 8 through 14


    0.3500    0.4000    0.4500    0.5000    0.5500    0.6000    0.6500


  Columns 15 through 21


    0.7000    0.7500    0.8000    0.8500    0.9000    0.9500    1.0000



y =


  Columns 1 through 7


    1.0000    1.0000    1.0000    1.0000    1.0002    1.0006    1.0015


  Columns 8 through 14


    1.0036    1.0073    1.0138    1.0242    1.0402    1.0640    1.0984


  Columns 15 through 21


    1.1475    1.2163    1.3125    1.4469    1.6358    1.9041    2.2918


>> [t,y]=euler([0,1],1,40)


t =


  Columns 1 through 7


         0    0.0250    0.0500    0.0750    0.1000    0.1250    0.1500


  Columns 8 through 14


    0.1750    0.2000    0.2250    0.2500    0.2750    0.3000    0.3250


  Columns 15 through 21


    0.3500    0.3750    0.4000    0.4250    0.4500    0.4750    0.5000


  Columns 22 through 28


    0.5250    0.5500    0.5750    0.6000    0.6250    0.6500    0.6750


  Columns 29 through 35


    0.7000    0.7250    0.7500    0.7750    0.8000    0.8250    0.8500


  Columns 36 through 41


    0.8750    0.9000    0.9250    0.9500    0.9750    1.0000



y =


  Columns 1 through 7


    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000


  Columns 8 through 14


    1.0001    1.0002    1.0004    1.0007    1.0012    1.0020    1.0030


  Columns 15 through 21


    1.0044    1.0063    1.0087    1.0120    1.0161    1.0213    1.0278


  Columns 22 through 28


    1.0358    1.0457    1.0576    1.0721    1.0894    1.1102    1.1350


  Columns 29 through 35


    1.1645    1.1994    1.2408    1.2899    1.3481    1.4171    1.4991


  Columns 36 through 41


    1.5970    1.7140    1.8545    2.0243    2.2303    2.4823

(d)

> [t,y]=euler([0,1],1,10)


t =


  Columns 1 through 7


         0    0.1000    0.2000    0.3000    0.4000    0.5000    0.6000


  Columns 8 through 11


    0.7000    0.8000    0.9000    1.0000



y =


  Columns 1 through 7


    1.0000    1.0000    1.0001    1.0009    1.0049    1.0178    1.0496


  Columns 8 through 11


    1.1176    1.2517    1.5081    2.0028


>> [t,y]=euler([0,1],1,20)


t =


  Columns 1 through 7


         0    0.0500    0.1000    0.1500    0.2000    0.2500    0.3000


  Columns 8 through 14


    0.3500    0.4000    0.4500    0.5000    0.5500    0.6000    0.6500


  Columns 15 through 21


    0.7000    0.7500    0.8000    0.8500    0.9000    0.9500    1.0000



y =


  Columns 1 through 7


    1.0000    1.0000    1.0000    1.0000    1.0002    1.0006    1.0015


  Columns 8 through 14


    1.0036    1.0073    1.0138    1.0242    1.0402    1.0640    1.0984


  Columns 15 through 21


    1.1475    1.2163    1.3125    1.4469    1.6358    1.9041    2.2918


>> [t,y]=euler([0,1],1,40)


t =


  Columns 1 through 7


         0    0.0250    0.0500    0.0750    0.1000    0.1250    0.1500


  Columns 8 through 14


    0.1750    0.2000    0.2250    0.2500    0.2750    0.3000    0.3250


  Columns 15 through 21


    0.3500    0.3750    0.4000    0.4250    0.4500    0.4750    0.5000


  Columns 22 through 28


    0.5250    0.5500    0.5750    0.6000    0.6250    0.6500    0.6750


  Columns 29 through 35


    0.7000    0.7250    0.7500    0.7750    0.8000    0.8250    0.8500


  Columns 36 through 41


    0.8750    0.9000    0.9250    0.9500    0.9750    1.0000



y =


  Columns 1 through 7


    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000


  Columns 8 through 14


    1.0001    1.0002    1.0004    1.0007    1.0012    1.0020    1.0030


  Columns 15 through 21


    1.0044    1.0063    1.0087    1.0120    1.0161    1.0213    1.0278


  Columns 22 through 28


    1.0358    1.0457    1.0576    1.0721    1.0894    1.1102    1.1350


  Columns 29 through 35


    1.1645    1.1994    1.2408    1.2899    1.3481    1.4171    1.4991


  Columns 36 through 41


    1.5970    1.7140    1.8545    2.0243    2.2303    2.4823


6.For the initial value problems in Exercise 4,make a log-log plot of the error of Euler's Method at t=2 as a function of h=0.1×2^(-k) for 0≤k≤5.







上一篇:没有了    下一篇:没有了

Copyright ©2018    计算数学达人 All Right Reserved.
技术支持:自助建站 | 领地网站建设 |短信接口 版权所有 © 2005-2018 lingw.net.粤ICP备16125321号 -5