Вы находитесь на странице: 1из 23

-

6
:

( )

:
:

_______________
_____

: 14

..

__________________
" ___ " ______________ 2006 .

2006

6.1.
() 1

y '(t ) = f (t , y (t )), t [t0 ,T ],


y (t0 ) = y0

(1)

.
:
1.
2.
3.
4.
5.
6.

: f , y0 .
eyler (. 6.B),
h=0.1 .
rkfixed MATHCAD,
h=0.1 (. 6.B).
.
.
.
:

e = max | y (ti ) - yi | ;

y (ti ) yi -
0i N
ti , i=1,..N;
b) ( ) (. 6.C).
7. , h=h* , ,
(. . 6), , -
h=0.1.
. . 7 , h
.
a)

:
:
y k +1 = y k + h f ( x k , y k )
f ( x k , y k ) - .

.
.
:
h
y i +1 = y i + ( K 1 + 2 K 2 + 2 K 3 + K 4 )
6
K1 = f ( xi , yi )
K 2 = f ( xi + 0.5h, y i + 0.5h K 1 )
K 3 = f ( xi + 0.5h, y i + 0.5h K 2 )
K 4 = f ( xi + h, y i + h K 3 )

( ):
,

.
( )
:
y (t i ) - y i( h / 2) e i( h ) ,
y 2(hi / 2 ) - y i( h )
e =
, i= 0, , n t i , h ,
2 p -1
p , y i(h ) y 2( hi / 2 ) - h h / 2
t i .
( h)
i

:
:

f ( t , y) :=

: y0 := 4

12
t

t0 := 1

T := 2

: h := 0.1

:
: N :=

T - t0

N = 10

i := 1 .. N
t i := t0 + i h

, ; :
eyler ( f , y0 , t0 , h , N ) :=

y0 y0
for i 0 .. N - 1

yi+ 1 yi + h f t0 + i h , yi
y

yE := eyler f , y0 , t0 , h , N

:
f - ;
y0 - ;
t0 -
;
h - ;
N - .

yE =

3.2

2.5893313298272

2.11066449620169

1.72682394083441

1.4128507237803

1.15148521647677

0.930484292506567

0.740968713539418

0.576372325196958

10

0.431755093734077


( - 4- ):
yRK4 := rkfixed ( y , t0 , T , N , f)

- ;
:
y - ;
t0- ;
T - ;
N - ;
f - .

rkfixed ,
, - .
0

yRK4 =

1.1

3.30576298486409

1.2

2.77774195868259

1.3

2.36681861272695

1.4

2.04076377359122

1.5

1.77771918609449

1.6

1.56243607225608

1.7

1.38401420013955

1.8

1.23449439708241

1.9

1.10795524063915

10

0.999917609225951

yTrue ( t ) :=

4
t

- .

3
yEi
2

yRK4i , 1

()

yTrue t i

1.2

1.4

1.6

1.8

ti

:
:

()

()

eE_1i := yTrue t i - yEi

eRK4_1i := yTrue ti - yRK4i , 1

max_e_E := max ( eE_1)

max_e_RK4 := max ( eRK4_1)

max_e_E = 0.568244906265923

max_e_RK4 = 8.23907740494789 10

-5

:
h/2:
h2 :=

h
2

N2 :=

T - t0

N2 = 20

h2

yEh2 := eyler f , y0 , t0 , h2 , N2

yRK4h2 := rkfixed ( y , t0 , T , N2 , f )

:
zEi := yEh22 i - yEi

zRK4i :=

i := 0 .. N

(yRK4h21 )2 i - (yRK41 )i
15

:
max ( zE) = 0.285306411369347

-6

max ( zRK4) = 5.14246690531313 10

Mmax:
Mmax( y , yr , n) :=

max 0
for i 0 .. n
max yi - yr i

yi - yr i > max

if

max

,
.
get_h ( h , e , yTrue) :=

s0 1
while s0 > e
T - t0

for i 0 .. N
ti t0 + i h

()

yti yTrue ti

yE eyler f , y0 , t0 , h , N

s0 Mmax( yt , yE , N )
s1 h
h

h
2

6.86646663453638 10- 5

get_h ( 0.1 , max_e_RK4 , yTrue) =

-5
1.220703125 10

-5

1.220703125 10

- h=0.1
: -
, ,
.
.

6.2. 2

mx + Hx + kx = f (t ) , t [0,T ],
x(0) = x0
x(0) = v0

m, . x(t)
, H , , k
, f(t) . :

x0

t=0, v0 .
[0,T] (I, II, III)
. ( )
x(t) ,
. ,
.
:
1. 1 :

x1 = x2

f (t ) - Hx2 - kx1
m
x1(0) = x0
x2 =

(2)

x2 (0) = v0
2. (2)
rkfixed MATHCAD (. 7.B) h=0.1.
3. .
.
4. .
I:
H ( t ) := 1
X0 := 0

K := 1

m := 1

V0 := 0

f ( t) := cos ( t )

t0 := 0

: h := 0.1

T := 34

I:
:

N :=

T - t0
h

(1)
rkfixed:
f1 ( t , x1 , x2) := x2

x :=

X0

V0

f2 ( t , x1 , x2) :=

D ( t , x) :=

f ( t) - H ( t) x2 - K x1

f1 ( t , x0 , x1)

f2 ( t , x0 , x1)

xRK4 := rkfixed ( x , t0 , T , N , D )

15

get_minimum ( m , n1 , n2) :=

min 10

for i n1 .. n2
if m i , 1 < min
min m i , 1
result0 m i , 0
result1 m i , 1
result2 i
result
get_maximum ( m , n1 , n2) :=

max 0
for i n1 .. n2
if m i , 1 > max
max m i , 1
result0 m i , 0
result1 m i , 1
result2 i
result

i := 0 .. N
17.3

get_minimum ( xRK4 , 0 , 340) = -0.999910402134673

173

xRK4i , 1

10

20

30

26.7000000000001

get_maximum ( xRK4 , 0 , 340) = 0.99999715251772

267

xRK4i , 0

II:
H ( t ) := 1
X0 := 0

K := 1

m := 14 f ( t) := cos ( t )

V0 := 0

t0 := 0

T := 34

: h := 0.1

II:
:

N :=

T - t0
h

(1)
rkfixed:

f1 ( t , x1 , x2) := x2

x :=

X0

V0

f2 ( t , x1 , x2) :=

D ( t , x) :=

f ( t) - H ( t) x2 - K x1
m

f1 ( t , x0 , x1)

f2 ( t , x0 , x1)

xRK4 := rkfixed ( x , t0 , T , N , D )

i := 0 .. N
12.4

get_minimum ( xRK4 , 0 , 340) = -0.123912023170379

124

0.1

xRK4i , 1

2.9

get_maximum ( xRK4 , 0 , 340) = 0.117792615900578

29

0.1
0

20
xRK4i , 0

III:
H ( t ) := 1
X0 := 0

K := 1

m := 28 f ( t) := cos ( t )

V0 := 0

t0 := 0

: h := 0.1

T := 34

III:
:

N :=

T - t0
h

(1)
rkfixed:
f1 ( t , x1 , x2) := x2

x :=

X0

V0

f2 ( t , x1 , x2) :=

D ( t , x) :=

f ( t) - H ( t) x2 - K x1

f1 ( t , x0 , x1)

f2 ( t , x0 , x1)

xRK4 := rkfixed ( x , t0 , T , N , D )

xRK4i , 1

i := 0 .. N
18.7

get_minimum ( xRK4 , 0 , 340) = -0.060414912262805

187

get_maximum ( xRK4 , 0 , 340) = 0.064517539485313

30

20
xRK4i , 0

IV:
H ( t ) := 2
X0 := 0

K := 4

m := 8

V0 := 0

f ( t) := 10

t0 := 0

: h := 0.1

T := 34

IV:
:

N :=

T - t0
h

(1)
rkfixed:
f1 ( t , x1 , x2) := x2

x :=

X0

V0

f2 ( t , x1 , x2) :=

D ( t , x) :=

f ( t) - H ( t) x2 - K x1
m

f1 ( t , x0 , x1)

f2 ( t , x0 , x1)

10
f ( z)
9.99

xRK4 := rkfixed ( x , t0 , T , N , D )

i := 0 .. N

9.98

20

40

60

z
4

xRK4i , 1

0
get_minimum ( xRK4 , 0 , 340) = 0

0

20
xRK4i , 0

4.5

get_maximum ( xRK4 , 0 , 340) = 3.92190222525123

45

:
,
.
, ..
.
.
, ,
.
,
, .
,
.
.
6.3. 1 (1),

1. ,
2. ,
3. - ,
4. ,
5. - 4 ( )
h =

T - t0
h / 2 .
100

(. 6.C).
( h / 2), ,
. .

:
( ):
,
.
(
) :

y (t i ) - y i( h / 2) e i( h ) ,
y 2( hi / 2 ) - y i( h )
=
, i= 0, , n t i , h , p
e
2 p -1
(h )
( h / 2)
, y i y 2 i
- h h / 2 t i .
( h)
i

y i , = y 2( hi / 2) + e i( h ) , i=0,, n.

1- :

y i +1 = y i + hf ( x i , y i )
1- :

y i +1 = y i + hf ( xi +1 , y i +1 )
2-

y i +1 = y i + hf ( xi + 0.5h, yi + 0.5hf ( xi , y i ))
- 2- ( -):

h
yi +1 = yi + ( f (ti , yi ) + f (ti +1, yi +1 ))
2

yi +1 = yi + hf (ti , yi ),

- 4- :

h (1)
(k i + 2k i( 2) + 2k i(3) + k i( 4) )
6
= f ( xi , y i ) , k i( 2) = f ( x i + 0.5h, y i + 0.5hk i(1) )

y i +1 = y i +
k i(1)

k i( 3) = f ( xi + 0.5h, yi + 0.5hk i( 2) ) , ki( 4) = f ( xi + h, yi + h ki( 3) )


:
:

f ( t , y) := -t y - t

y0 := 3

N := 100

i := 0 .. N

t0 := 0

:
: h :=

T - t0
N
-

yTrue ( t ) := 2 - t + e

h = 0.01

xi := t0 + i h

1) :
eyler ( f , y0 , t0 , h , N ) :=

y0 y0
for i 0 .. N - 1

yi+ 1 yi + h f t0 + i h , yi
y

T := 1

yE := eyler f , y0 , t0 , h , N

E i := yE22 i - yEi

yE2 := eyler f , y0 , t0 ,

h
2

, 2N
mE := max ( E

yE_C i := yE22 i + Ei

mE = 0.03319307271477

( )

yTrue xi

2.5

yE2 2 i
yE_Ci

1.5

0.2

0.4

0.6

0.8

xi

( )

yTrue xi

2.24

yE22 i
yE_Ci

2.22

2.2
0.72

0.73

0.74
xi

2) :
eylerEnh ( f , y0 , t0 , h , N ) :=

y0 y0
for i 0 .. N - 1

yi+ 1 yi + h f t0 + i h + 0.5 h , yi + 0.5 h f t0 + i h , yi

))

yEEnh := eylerEnh f , y0 , t0 , h , N
E i := yEEnh22 i - yEEnhi

yEEnh2 := eylerEnh f , y0 , t0 ,

yEEnh_Ci := yEEnh22 i + Ei

h
2

, 2N

mEEnh := max ( E

)
-5

mEEnh = 5.92028716900001 10

( )

yTrue xi

2.5

yEEnh22 i
yEEnh_Ci

1.5

0.2

0.4

0.6

0.8

xi

( )

yTrue xi

2.24

yEEnh22 i
yEEnh_Ci

2.22

2.2
0.72

0.73

0.74
xi

3) - 2- ( "-"):
eylerKoshy ( f , y0 , t0 , h , N ) :=

y0 y0
t10 1
for i 0 .. N - 1
yi+ 1 yi +

h
2

yEK := eylerKoshy f , y0 , t0 , h , N
E i := yEK22 i - yEKi

f t0 + i h , yi + f t0 + ( i + 1 ) h , yi + h f t0 + i h , yi

yEK2 := eylerKoshy f , y0 , t0 ,

yEK_Ci := yEK22 i + Ei

h
2

, 2N

( )

yTrue xi

mEK := max ( E

2.5

-5

mEK = 6.63667365979669 10

yEK2 2 i
yEK_Ci

1.5

0.2

0.4

0.6

0.8

xi

( )

yTrue xi

2.24

yEK22 i
2.22

yEK_Ci

2.2
0.72

0.73

0.74
xi

4) :
ImplicitEyler ( f , y0 , t0 , h , N ) :=

y0 y0
15

ys 10

for i 0 .. N - 1

yi+ 1 yi + h f t0 + i h , yi
while

- 15

yi+ 1 - ys > 10

ys yi+ 1
yi+ 1 yi +

h
2

f t0 + i h , yi + f [ t0 + ( i + 1 ) h , ys]

yIE := ImplicitEyler f , y0 , t0 , h , N
E i := yIE22 i - yIEi

yIE2 := ImplicitEyler f , y0 , t0 ,

yIE_C i := yIE22 i + Ei

, 2N

( )

yTrue xi

2.5

yIE22 i
yIE_Ci

1.5

0.2

0.4

0.6

0.8

xi

mIE := max ( E

)
-5

mIE = 2.66292374223529 10

( )

yTrue xi

2.24

yIE22 i
2.22

yIE_Ci

2.2
0.72

0.73

0.74
xi

5) - 4- :
RungeKutt ( f , y0 , t0 , h , N ) :=

y0 y0
for i 0 .. N - 1

(
)
k2i f ( t0 + i h + 0.5 h , yi + 0.5 h k1i)
k3i f ( t0 + i h + 0.5 h , yi + 0.5 h k2i)
k4i f ( t0 + i h + h , yi + k3i h)

k1i f t0 + i h , yi

yi+ 1 yi +

h
6

k1i + 2 k2i + 2 k3i + k4i

yRK := RungeKutt f , y0 , t0 , h , N
E i := yRK22 i - yRKi

yRK2 := RungeKutt f , y0 , t0 ,

yRK_Ci := yRK22 i + Ei

h
2

, 2N

mRK := max ( E

- 10

mRK = 4.93886169201403 10

( )

yTrue xi

2.5

yRK22 i
yRK_Ci

1.5

0.2

0.4

0.6

0.8

xi

( )

yTrue xi

2.24

yRK22 i
yRK_Ci

2.22

2.2
0.72

0.73

0.74
xi

:
1) :
mE = 0.03319307271477

2) :
-5

mEEnh = 5.92028716900001 10

3) - 2- ( "-"):
-5

mEK = 6.63667365979669 10

4) :
-5

mIE = 2.66292374223529 10

5) - 4- :
- 10

mRK = 4.93886169201403 10

: -
.
.
,
, -. ,

,
,
, -.
-,
.

6.4. 3

a0 y + a1 y + a2 y + a3 y = f (t )
y ( A) = b1 , y( A) = b2 , y( A) = b3

[A,B] rkfixed MATHCAD h=0.1 h=0.05


1 . . ,
h=0.05.

:
3 1 :

y1 = y2
y 2 = y3
f (t ) - a1 y3 - a2 y 2 - a3 y1
a0
y1 ( A) = b1 , y 2 ( A) = b2 , y3 ( A) = b3 .
y3 =

:
: f ( t) := sin ( 2t) + 2 t - 1
:
a0 := 1

a1 := 1.4

A := 0
a2 := 1.88

: h := 0.1
:

B := 2

a3 := 18

y1 := 1.5

y2 := 2.9

y3 := 2

i := 0 .. N

t i := t0 + i h

N :=

B-A
h

(1)
rkfixed:
f1 ( t , y1 , y2 , y3) := y2
f2 ( t , y1 , y2 , y3) := y3
f3 ( t , y1 , y2 , y3) :=

f ( t ) - a1 y3 - a2 y2 - a3 y1
a0

f1 ( t , y0 , y1 , y2)

D ( t , y) := f2 ( t , y0 , y1 , y2)
f3 t , y , y , y
( 0 1 2)

y1
y := y2
y3

RK4_h := rkfixed ( y , A , B , N , D )

h=0.1
5

RK4_hi , 1

5
10
RK4_hi , 0

: h := 0.05

i := 0 .. N

h=0.05
5

RK4_h_2i , 1

5
10
RK4_h_2i , 0

h := 0.1

N :=

B-A
h

i := 0 .. N

N :=

B-A
h

RK4_h_2 := rkfixed ( y , A , B , N , D )

:
ERK4i :=

RK4_h_22 i , 1 - RK4_hi , 1
15

-6

max ( ERK4) = 6.9292724536633 10

: 3-
1- . ,
, 6.9292724536633 10- 6.

6.5. 2-
:

y + p y + q y = f (t )
y (a) = b1 , y (a ) = b2

1- , t [ A, B ]
- e = 10 .
:
1. 1- :
-3

y = z
z = f (t ) - p z - q y

y (a ) = b1
z (a) = b2
2.

(. 6.C) - c

h=
3.
4.
5.

B-A
.
10


, e.

. ,
.
. .

:
y = f (t , y , z )
z = g (t , y , z )

y (t 0 ) = y 0
z (t 0 ) = z 0
ti = t 0 + h i h
y i +1 = y i + hf (t i , y i , z i )

z i +1 = y i + hg (t i , y i , z i )

( yi , z i )

y = f (t , y , z )
z = g (t , y , z )

.
1- :
y
(
t
)
=
y
0
0

z (t 0 ) = z 0
t i = t 0 + h i , h - , ( yi , z i ) ,
, :
y i +1 = y i + hf (t i , y i , z i )

z i +1 = y i + hg (t i , y i , z i )

y i +1 = y i + h ( f (t i , yi , z i ) + f (t i +1 , y i +1 , z i +1 )) .
2

z i +1 = z i + 2 ( g (t i , yi , z i ) + g (t i +1 , y i +1 , z i +1 ))
:
-t

f ( t) := 14 t e
A := 0
i := 0 .. N

B := 4.3

b1 := 2

b2 := -0.4

t i := t0 + i h

f1 ( t , y , z ) := z

p := 3

q := -4

t0 := 0

t 0 := 0
-t

f2 ( t , y , z ) := 14 t e

- pz - q y

:
:
7 -t
7 - t 14 - 4 t -19 14 t 111
y ( t) := - e t e e

+
e
3
18
5
315
5
140

-:
EK ( f , g , y0 , z0 , t0 , B , N ) :=

B - t0
N

y0 y0
z 0 z0
for i 0 .. N

y_i+ 1 yi + h f t0 + i h , yi , z i

z_i+ 1 z i + h g t0 + i h , yi , z i
yi+ 1 yi +
z i +1 z i +
y

h
2
h
2

f t0 + i h , yi , z i + f t0 + ( i + 1 ) h , y_i + 1 , z_i +1

g t0 + i h , yi , z i + g t0 + ( i + 1 ) h , y_i + 1 , z_i +1

h=(B-A)/10 :
N := 10

i := 0 .. N

h :=

B-A
N

t i := t0 + i h

ek10 := EK ( f1 , f2 , b1 , b2 , t0 , B , N )
200
150

( )

y ti

ek10i

100
50

ti

N,
10- 3
get_N :=

N 10
e1
-3

while e > 10

ek1 EK ( f1 , f2 , b1 , b2 , t0 , B , N )
ek2 EK ( f1 , f2 , b1 , b2 , t0 , B , 2 N )
for j 0 .. N
Ej

ek22 j - ek1 j
3

e max ( E)
N 2 N
N
d := 64
N := get_N

i := 0 .. N

N = 2560

h :=

B-A
N

N2 :=

N
d

N2 = 40

j := 0 .. N2

EK_res := EK ( f1 , f2 , b1 , b2 , t0 , B , N )

t i := t0 + i h

h2 :=

B-A
N2

t2 j := t0 + j h2

200

150

( )

y t2j

EK_resj d

100

50

0.5

1.5

2.5

3.5

4.5

t2j

:
max ( y , s , N ) :=

E0
max 0
for i 0 .. N

()

E si - y ti

max E if E > max


max
-4

max ( y , EK_res , N ) = 3.91066975566901 10

:


-.
3.91066975566901 10- 4 10- 3.