You are on page 1of 31

Experiments in Mathematics

1 Matlab
.
2 Matlab .

1 .
2 .
3
4 .

MATLAB

Matlab

2
3


:
dsolve( 1, 2, n, , )

: D D2D3
. D
.
d2y

0 D2y=0.

2
dx
1 du
2 .
1 u

dt
dsolve('Du=1+u^2','t')

u = tg(t-c)

To
Matlab ff1

d2y
dy

4 29 y 0
2
dx
dx
y (0) 0, y ' (0) 15
: y=dsolve('D2y+4*Dy+29*y=0','y(0)=0,Dy(0)=15','x')
To
Matlab ff2
: y =3e-2xsin 5x

.
dx
dt 2 x 3 y 3 z
dy
4 x 5 y 3z

dt
dz 4 x 4 y 2 z
dt


[x,y,z]=dsolve('Dx=2*x-3*y+3*z','Dy=4*x-5*y+3*z','Dz=4*x-4*y+2*z', 't')
x=simple(x)
% x
y=simple(y)
To
z=simple(z)

Matlab ff3

x = (c1-c2+c3+c2e -3t-c3e-3t)e2t
y = -c1e-4t+c2e-4t+c2e-3t-c3e-3t+c1-c2+c3)e2t
z = (-c1e-4t+c2e-4t+c1-c2+c3)e2t

y' f(x, y)

x 0
y(x 0 ) y 0
xx0 x1 x 2 x n
y(x1 ),
y ( x 2 ),, y ( x n ) y1 , y 2 ,, y n


x i 1 xi h, i 0,1,2, n 1,
y' f(x, y)

y(x 0 ) y 0

h
y ' ( x)

y ( x h) y ( x )
h

y i 1 y i hf ( xi , y i )
i 0,1,2, , n - 1

y0 y( x0 )

2
y=f(x,y), xi xi+1
y ( x ) y ( x ) x f (t , y (t ))dt xi 1 xi [ f ( x , y ( x )) f ( x , y ( x ))]
i 1

i 1

xi

i 1

i 1

h
y i 1 y i [ f ( xi , y i ) f ( xi 1 , y i 1 )]

2
y 0 y ( x0 )

y i(01) y i hf ( xi , y i )

h
( k 1)
(k )
y

[
f
(
x
,
y
)

f
(
x
,
y
i

1
i
i
i
i

1
i
1 )] k 0,1,2,

y i(k11) y i(k1)
y i 1 yi k11
y i 2

3
-

O hk+1 k h
k
k

Matlab

[t x]=solver f,ts,x0,options

ode45
ode23
ode113
ode15s
ode23s

m-

ts=[t0 tf
] t0 tf

ode23 2/3 - -
ode45 4/5 - -

( 10-3, 106
),
options=odeset reltol,rt,abstol,at ,
rt at .

1 n x0 x n
m- x .
2 Matlab
.

d 2x
2 dx

1000(1 x ) x 0
4
2
dt
dt

x(0) 2; x' (0) 0


: y1=x y2=y1

y1 ' y2

y2 ' 1000(1 y ) y2 y1

y1 (0) 2, y2 (0) 0

2
1

2
1.5
1
0.5
0

1 m- vdp1000.m
function dy=vdp1000(t,y)
dy=zeros(2,1);
dy(1)=y(2);
dy(2)=1000*(1-y(1)^2)*y(2)-y(1);
-0.5

-1

-1.5

-2

-2.5

2 t0=0 tf=3000
[T,Y]=ode15s('vdp1000',[0 3000],[2 0]);
plot(T,Y(:,1),'-')
3

500

1000

1500

2000

2500

To
Matlab ff4

3000

y1 ' y2 y3

y2 ' y1 y3
y3 ' 0.51 y1 y2
y1 (0) 0, y2 (0) 1, y3 (0) 1

1 m- rigid.m
function dy=rigid(t,y)
dy=zeros(3,1);
dy(1)=y(2)*y(3);
dy(2)=-y(1)*y(3);
dy(3)=-0.51*y(1)*y(2);

1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1

10

12

To
Matlab ff5

2 t0=0 tf=12
[T,Y]=ode45('rigid',[0 12],[0 1 1]);
plot(T,Y(:,1),'-',T,Y(:,2),'*',T,Y(:,3),'+')
3

y1 y2 * y3 + .


x A(1, 0)
.
v0( ) y 5v0
.

t P(x(t), y(t))

PQ
OP P

v0 t y
y'
1 x
v0 t (1 x) y ' y

(1)

OP AQ 5

1 y ' 2 dx 5v0 t

(2)

Q(1, v0 t )

(1),(2) t :
1
(1 x ) y"
1 y '2
(3)
5
: y (0) 0 y ' (0) 0
:
4

5
5
5
5
5
y (1 x) (1 x)
8
12
24
x 1 y 5 (1, 5 ) .

24

24

: t y

v0

chase1

5 . v =1, t=0.21 .
0
24v0
To Matlab(chase1)

( )
y1=y,y2=y1 3
1
(1 x) y ' '
1 y2
5

y '1 y2

y ' 1 1 y 2 /(1 x)
1
2 5

1. m- eq1.m
function dy=eq1(x,y)
dy=zeros(2,1);
dy(1)=y(2);
dy(2)=1/5*sqrt(1+y(1)^2)/(1-x);
2. x0=0 xf=0.9999 ff6.m
x0=0 xf=0.9999
[x,y]=ode15s('eq1',[x0 xf],[0 0]);
plot(x,y(:,1),b.')
hold on
To Matlab(ff6)
y=0:0.01:2;
plot(1,y,b*')
: 1 0.2

( )
t (X(t) Y(t)) (x(t) y(t)).

dx 2
dy 2
( ) ( ) w2
dt
dt

2.

dx

X x
dt

0
dy

Y y

dt
w
dx

( X x)
dt
2
2
(
X

x
)

(
Y

y
)


dy
w

(Y y )
dt
( X x) 2 (Y y ) 2
3 v0 x=1 v0=1
w=5 X=1 Y=t

5
dx
(1 x)
dt
2
2
(1 x) (t y )

5
dy

(t y )

2
2
(1 x) (t y )
dt
x(0) 0, y (0) 0

4.
m- eq2.m
function dy=eq2(t,y)
dy=zeros(2,1);
dy(1)=5*(1-y(1))/sqrt((1-y(1))^2+(t-y(2))^2);
dy(2)=5*(t-y(2))/sqrt((1-y(1))^2+(t-y(2))^2);
t0=0 tf=2 chase2.m
[t,y]=ode45('eq2',[0 2],[0 0]);
Y=0:0.01:2;
plot(1,Y,'-') hold on
To Matlab(chase2)
plot(y(:,1),y(:,2),'*')

5. 1

2
1
1 0.2
. chase2.m t
f
tf=1 0.5,0.25,, tf=0.21
2.
To Matlab(chase2)
t=0.21 1 0.21


v=1 ,
: x=10+20cost, y=20+5sint. .
, w ,
. w=20,w=5 .
1.
t (X(t) Y(t)) (x(t)
y(t)).
X=10+20cost, Y=20+15sint, (0,0) ,
:

w
dx

(10 20 cos t x )
dt
2
2
(10 20 cos t x ) ( 20 15 sin t y )

w
dy

( 20 15 sin t y )
dt
2
2
(10 20 cos t x ) ( 20 15 sin t y )

y ( 0) 0
x (0) 0,

2.
(1) w=20 , m- eq3.m :
function dy=eq3(t,y)
dy=zeros(2,1);
dy(1)=20*(10+20*cos(t)-y(1))/sqrt
((10+20*cos(t)-y(1))^2+(20+15*sin(t)-y(2))^2);
dy(2)=20*(20+15*sin(t)-y(2))/sqrt
((10+20*cos(t)-y(1))^2+(20+15*sin(t)-y(2))^2);
t0=0 tf=10 chase3.m
t0=0;tf=10;
[t,y]=ode45('eq3',[t0 tf],[0 0]);
T=0:0.1:2*pi;
X=10+20*cos(T);
Y=20+15*sin(T);
To Matlab(chase3)
plot(X,Y,'-')
hold on
plot(y(:,1),y(:,2),'*')
chase3.m tf , tf=5, 2.5, 3.5,, 3.15 ,
.

(2) w=5
m- eq4.m :
function dy=eq4(t,y)
dy=zeros(2,1);
dy(1)=5*(10+20*cos(t)-y(1))/sqrt
((10+20*cos(t)-y(1))^2+(20+15*sin(t)-y(2))^2);
dy(2)=5*(20+15*sin(t)-y(2))/sqrt
((10+20*cos(t)- y(1))^2+(20+15*sin(t)-y(2))^2);
t0=0 tf=10 chase4.m

t0=0;tf=10;
[t,y]=ode45('eq4',[t0 tf],[0 0]);
T=0:0.1:2*pi;
X=10+20*cos(T);
To Matlab(chase4)
Y=20+15*sin(T);
plot(X,Y,'-')
hold on
chase3.m tf , tf=20, 40, 80,,
plot(y(:,1),y(:,2),'*')
, .


Ancona
,

1914
11.9
1919
27.3

1915
21.4
1920
16.0

1916
22.1
1921
15.9

1917
21.2
1922
14.8

1918
36.4
1923
19.7

V.Volterra
.

1
x1 (t ) t x 2 (t ) t

r1 r2
1 2 .
e

2
1
2

dx1
x1 (r1 1 x 2 )
dt
dx 2
x 2 ( r2 2 x1 )
dt

Volterra
.

Matlab .
x1 (0) x10 x 2 (0) x 20
r1 1, 1 0.1, r2 0.5, 2 0.02, x10 25, x 20 2

t 15

x1' x1 (1 0.1x 2 )
'
x 2 x 2 (0.5 0.02 x1 )
x (0) 25, x (0) 2
2
1
m- shier.m
function dx=shier(t,x)
dx=zeros(2,1);
dx(1)=x(1)*(1-0.1*x(2));
dx(2)=x(2)*(-0.5+0.02*x(1));
shark.m
[t,x]=ode45('shier',[0 15],[25 2]);
plot(t,x(:,1),'-',t,x(:,2),'*')
plot(x(:,1),x(:,2))

To Matlab(shark)

x1 (t ) x 2 (t ) *.

( x1 , x 2 )

30

100
90

25

80

20

70
60

15

50
40

10

30

20
10
0

10

15

0
0

20

40

60

80

x1 t x2 t
x1 t x2 t

100


e
r1 r1-e r2 r2+e
dx1
dt x1[(r1 e) 1 x2 ]
dx
2

x2 [(r2 e) 2 x1 ]
dt
r1 1, 1 0.1, r2 0.5, 2 0.02, x
25, x
2
1 0
2 0
e=0.3, e=0.1,
:
dx1
dx1

dt x1 (0.9 0.1x2 )
dx
2
x2 (0.6 0.02 x1 )

dt
x1 (0) 25, x2 (0) 2

x1 (0.7 0.1x2 )

dt
dx
2
x2 (0.8 0.02 x1 )

dt
x1 (0) 25, x2 (0) 2

:
1 m- shier1.m shier2.m

2 shark1.m,
x2(t)/[x1(t)+x2(t)]
0.8

To Matlab(shark1)

0.7
0.6
0.5

0.4
0.3
0.2
0.1
0

10

15


1. a .
.
2. .
1 x y
k r
.
2 k(x) r(x)
.
1. 2. :

3.

You might also like