﻿ 15074116 缪于宏 12 - 计算数学达人 - 专，学者，数值代数，微分方程数值解

### 15074116 缪于宏 12

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 Euler’s 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

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:

http://weibo.com/u/5745282594/home?wvr=5&uut=fin&from=reg

2.when h=0.05

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:

http://weibo.com/u/5745282594/home?wvr=5&uut=fin&from=reg

3 when h=0.025

>> 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:

http://weibo.com/u/5745282594/home?wvr=5&uut=fin&from=reg

(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

>> 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:

http://weibo.com/u/5745282594/home?wvr=5&uut=fin&from=reg

2.when h=0.05

>> 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:http://weibo.com/u/5745282594/home?wvr=5&uut=fin&from=reg

3.when h=0.025

>> 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:http://weibo.com/u/5745282594/home?wvr=5&uut=fin&from=reg

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.