现在时间是:
当前位置:首 页 >> 数值分析(英)>> 教学区>> 文章列表

15074131陈霄霄15数31第13次作业

作者:   发布时间:2017-06-13 22:13:11   浏览次数:36

6.1Exercises

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

(a)y=t;

(d)y=5t^4*y

Sol

(a)

dy/dt=t

Dy=t*dt

Y=(1/2)*t^2+c

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

Therefore,y=(1/2)*t^2+1

(d)

dy/dt=5t^4*y

ln|y|=t^5+c

y=e^( t^5+c)

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

therefore,y=e^(t^5)

 

6.1 Computer problems

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

(a)y=t;

Code:

function z=ydot(t,y)

z=t;

function y=eulerstep(t,y,h)

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

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)

1.   When h=0.1

 

answer:

syms t;t=0:0.1:1;

>> y=(1/2)*t.^2+1;

>>  plot(t,y,'g*');

hold on

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

results:

 

2.when h=0.05

Answer:

syms t;t=0:0.05:1;

y=(1/2)*t.^2+1;

 plot(t,y,'g*');

hold on

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

 

Results:

 

3 when h=0.025

Answer:

>> clear

>>  syms t;t=0:0.025:1;

y=(1/2)*t.^2+1;

 plot(t,y,'g*');

hold on

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

 

Results:

 

(d) y=5t^4*y

Code:

function z=ydot(t,y)

z=5*t^4*y;

function y=eulerstep(t,y,h)

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

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)

 

1.   When h=0.1

Answer:

>> clear

syms t;t=0:0.1:1;

>> y=exp(t.^5);

>> plot(t,y,'g*');

>> hold on

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

 

results:

 

2.when h=0.05

Answer:

>> syms t;t=0:0.05:1;

>> y=exp(t.^5);

plot(t,y,'g*');

hold on

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

Results:

 

3.when h=0.025

Answer:

>> syms t;t=0:0.025:1;

y=exp(t.^5);

plot(t,y,'g*');

hold on

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

Results:

 

 

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

 







Copyright ©2017    计算数学达人 All Right Reserved.

Powered by LingCms 版权所有 © 2005-2017 Lingd.Net.粤ICP备16125321号 -4