﻿ 15074131陈霄霄15数31第13次作业 - 计算数学达人 - 专，学者，数值代数，微分方程数值解

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

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