Sei sulla pagina 1di 19

High Level Postgraduate Course in Aerospace Engineering

School of Aerospace Engineering of Rome





Lecture Notes for Cycle 1
Numerical Integration of Ordinary Differential Equations


The aim is to find a curve (with respect to time) having tangent direction defined by a vector field of
directions. Namely the usual formula
1

( ) x f x =

(1)
means that a vector f

is attached to any point x and we are looking for a curve ( ) x t such that its
tangent is equal to the vector ( ( )) f x t

.
The curve ( ) x t is called the solution of the differential equation (1) and a unique solution is
identified by the passage through a specified point at the initial time
0
t (time zero,
0
0 t = ):

0 0
( ) (0) x t x x = = (2)
Example 1
An easy differential equation is the following one:

0
(0)
x x
x x
=

(3)
Namely from the mathematical point of view we are seeking for a function x such that its derivative
is equal to the function itself: this is a property of the exponential function:

( )

t
t t t
de
x e x e e x
dt
= = = = =
Also the product of the exponential function by a constant makes the same job:
( )
( )

t
t t t
d ke
x ke x k e ke x
dt
= = = = =
In fact the general solution of the equation x x = is just
t
x ke = , and the particular solution required
by the problem (3) is given by the relationships:


1
Here and in the following the symbols and x x

both indicate vectors


0
0
(0)
(0)
x ke k
x x
= =

=

so
0
k x = , and the solution of (3) is:

0
( )
t
x t x e =

Example 2
A similar problem is the following:

0

(0)
x a x
x x
=

(4)
Since this problem is similar to problem (3) , let as try a solution similar to the one before:
( )
t
x t ke

=
First derive:


def
t
x ke x
x a x

= =



Then, by comparison, a = , and ( )
at
x t k e =
Now impose the passage through
0
x at time
0
0 t = :

0
0
(0)
(0)
a
x ke k
x x
= =

=

Then
0
k x = and the solution of (4) is
t
0
( )
a
x t x e =

Example 3
Till now we considered scalar differential equations: the above solution applies to the following
system of de-coupled differential equations
1 1 1
2 2 2
n n n
y y
y y
y y

(5)
Since the equations are decoupled, we have n solutions equal to the one obtained in Example 2:

1
2
1 1
2 2
( )
( )
( )
n
t
t
t
n n
y t c e
y t c e
y t c e

(5.1)


where
1 1
2 2
(0)
(0)
(0)
n n
c y
c y
c y
=




Example 4
Consider now the system of linear differential equations:

1 11 1 12 2 1
2 21 1 22 2 2
1 1 2 2
n n
n n
n n n nn n
x a x a x a x
x a x a x a x
x a x a x a x
= + + +

= + + +

= + + +


(6)

with initial conditions
1 10
2 20
0
(0)
(0)
(0)
n n
x x
x x
x x
=



That is in matrix form:

0

(0)
x A x
x x
=
=

(7)

where the vector x and the matrix A are equal to:
11 12 1
1
21 22 2
2
1 2
and
n
n
n
n n nn
a a a
x
a a a
x
x A
x
a a a
| |
| |
|
|
|
|
|
= =
|
|
|
| |
\
|
\




The difference with respect to Example 3 is that now the differential equations of the system are
paired. It would be nice to find a transformation of coordinates (a matrix T of constant entries )

y x T = (8)

such that the transformed system of differential equation in y coordinates has the same form of (4),
so we can find the solution ( ) y t easily and the required solution ( ) x t will be obtained by the
transformation T.
Let us try:

y

x T
x Ax AT y
=

= =


Then the differential equations in y coordinates are:

1
y T A T y

= (9)

It is of interest to determine the transformation T such that:

1
2 1
0 0
0 0
with =
0
n
T AT

| |
|
|
=
|
|
|
\





so the system (9) becomes:
y y =

which is exactly the matrix version of the system of differential equations (5).
The solution (5.1) can be used:
1
1
2 2
1 1 1
2 2 2
( )
0 0
( ) 0 0
( )
0 0
( )
n
n
t
t
t t
t
t
n
n n
y t c e c
e
c y t c e e
y t
c e
y t c e

| | =
| || |
|
| |
=
|
| |
= =
|
| |
|
| |
| |
|
= \ \
\


where ( )
1 2
, , ,
n
c c c are by now unknown constant terms.
On the other hand the required initial conditions
0
(0) x x = imply:

1
2
0
(0) (0)
n
c
c
x x Ty T
c
| |
|
|
= = =
|
|
|
\



then

1
2 1
0
n
c
c
T x
c

| |
|
|
=
|
|
|
\


It follows that the solution of problem (7) is given by the following formula:

1
2
1
0
0 0
0 0
( )
0 0
n
t
t
t
e
e
x t Ty T T x
e

| |
|
|
= =
|
|
|
\



The matrix is the matrix of the eigenvalues
2
of the matrix A and T is the matrix of the
eigenvectors of the matrix A.
To find the eigenvalues and eigenvectors of a matrix (especially if the number n is bigger than
three) it is convenient to relay to a numerical software using the command:
[T,Lambda]=eig(A);


Example 4.1
Let the following system of linear differential equations be given:
1 1 2
2 1 2
2
4 3
x x x
x x x
= +

= +

(10)
with initial conditions:
1
1
(0) 1
(0) 3
x
x
=

(11)
The matrix of the system is
2 1
4 3
A
| |
=
|
\


The eigenvalues and eigenfunctions of the matrix A are equal to:
[ , ] ( ) T Lambda eig A =
0.5393 0.3637 0.4384 0
,
0.8421 0.9315 0 4.5616
T Lambda
| | | |
= =
| |

\ \

That is

( ) * * inv T A T Lambda =

The solution of the problem (10)-(11) is then:

1
2
1
0.4384 t
1
0
4.5616 t
0.5393 0.3637 0.5393 0.3637 1 0 0
( )
0.8421 0.9315 0.8421 0.9315 3 0 0
t
t
e e
x t T T x
e e

| | | | | | | | | |
= =
| | | | |

\ \ \ \ \
(12)

where

1
1
0.5393 0.3637 1.1520 0.4497
0.8421 0.9315 1.0414 0.6669
T

| | | |
= =
| |

\ \


Now the analytic solution (12) will be compared with the numerical solution of the problem (10)-
(11) obtained by the following numerical program:

2
Here it is assumed for simplicity that all the eigenvalues of the matrix A are distinct




% program lin
close all % this command cancels all the figures
clear all % this command refreshes the memory
global a11 a12 a21 a22 % the parameters are shared with other programs
a11=2;
a12=1;
a21=4;
a22=3;
A=[a11 a12;a21 a22]; % the matrix A of the system (10)
x10=1;
x20=3;
X0=[x10 x20]'; % the vector of initial conditions (11)
tspan=[0 1]; % duration of integration
[tau,y]=ode45('linrk',tspan,XX0); %tau is the output time, y is the matrix where
X1=y(:,1); %the first row y(:,1) is the solution x1 the
X2=y(:,2); %second row y(:,2) is the solution x2
subplot(2,1,1) % the screen is divided in two rows and this plot is shown
plot(tau,X1,o) % in the first row by dots
subplot(2,1,2) % the screen is divided in two rows and this plot is shown
plot(tau,X2,o) % in the second row by dots


%program linrk it is the program defining the derivatives of the system (10)
function linrk=linrk(tau,y)
global a11 a12 a21 a22
a1=a11*y(1)+a12*y(2);
a2=a21*y(1)+a22*y(2);
linrk=[a1 a2]';

The following figure compares the numerical solutions X1 and X2 obtained by the programs lin,
linrk (plotted by dots) and the analytic solutions (12) (plotted by a continuous line). The good
agreement is apparent.


Time (s)

Example 5: Pendulum

The dynamics of a pendulum is represented by the equation:

sin( ) k =

(13)
where is the angular displacement from the vertical direction of the tip mass of the pendulum, see
Figure 1. The motion depends on the initial angle and the initial angular velocity, that is
0
0
(0)
(0)


=
=


For instance, let the tip mass be initially set along the vertical, that is (0) 0 = , with angular
velocity (0) 0.1 =

(point A in Figure 1). Because of this angular velocity the tip mass will move to
the right to reach a point of maximum angular deviation from the vertical direction (maximum ).
This state will be reached with zero angular velocity (point B in Figure 1). Then the angular
velocity becomes negative and the tip mass will move backwards toward the vertical position and
will reach such a state with the same initial velocity, but now in negative sense (point C in Figure 1).
The maximum negative amplitude will be reached with zero angular velocity (point D) . After
reaching point D the angular velocity becomes positive and the entire cycle is performed when the
tip mass crosses the vertical position with the same (positive) initial velocity (point E).



The pendulum motion can be obtained by the following numerical program which solves the
equation of motion (13) (a differential equadion of order two) in the equivalent form of a system
of two differential equations of order one:

sin( )
u
u k

(14)







% program pendulum
close all % this command cancels all the figures
clear all % this command refreshes the memory
global k % the parameters are shared with other programs
k=1;
phi0=0; % initial angle
phip0=0.1; % initial angular velocity
X0=[phi0 phip0]'; % the vector of initial conditions (11)
tspan=[0 6*pi]; % duration of integration
[t,y]=ode45('pendulumrk',tspan,X0);%tau is the output time,y is a matrix where
phi=y(:,1); %the first row y(:,1) is the angle phi
phip=y(:,2); %second row y(:,2) is the angular velocity
figure(1)
subplot(2,1,1) %the screen is divided in two rows and this plot is shown
plot(t,phi*180/pi) %in the first row: time history of the angle (deg)
subplot(2,1,2) %the screen is divided in two rows and this plot is shown
plot(t,phip*180/pi) %in the second row: time history of angular velocity (deg/s)
figure(2) %in this figure the phase space is shown
plot(phi*180/pi,phip*180/pi)
title(Phase space)
xlabel(Angle (deg))
ylabel(Angular velocity (deg/s))

%pendulumrk
function pendulumrk=pendulumrk(t,y)
global k
a1=y(2) ; % the first line of equation (14)
a2=-k*sin(y(1)) ; % the second line of equation (14)
pendulumrk=[a1 a2] ;



In the following figures the variation in time of the angle and of the angular velocity

are
shown.




In the next figure the phase plane
( )
,

is shown the five states A-E are shown in the plot.




Note that there is a function of the state variables that stay constant during the motion, that is an
integral of the motion. This is the pendulum energy:

( )
2
1
cos
2
E k =


In fact
( ) ( ) ( )
1
2 sin sin
2
dE
k k
dt
= + = +


and the term in the bracket is zero according to the equation of motion (13).

Then the energy at the beginning of the integration

( )
2
0 0 0
1
cos
2
E k =


must be equal to the energy evaluated along the numerical solution found:

0
Error E E =
The above formula measures the error of our numerical integration, since the difference
0
E E
should be equal to zero.
Then let us add the following commands to the program pendulum:

E0=0.5*phip0^2-k*cos(phi0);
E=0.5*phip^2-k*cos(phi);
Error=E0-E;
figure (4)
plot(t,Error)

The following figure shows the time variation of the Error function.



Note that Error is increasing and of order 1e-06: to get a better accuracy it is convenient to change
the values of the relative tolerance RelTol and of the absolute tolerance AbsTol in the file ode45.
A good choice is the following:

Tol=1e-012;
Tol0=1e-09;
options=odeset('RelTol',Tol0,'AbsTol',Tol);

Adding these commands to the program pendulum and substituting the command

[t,y]=ode45('pendulumrk',tspan,XX0);

with the command

[t,y]=ode45('pendulumrk',tspan,XX0, options);

the value of the error function becomes as in the following figure, thus the accuracy is by far
improved (of order 1e-12). We suggest to adopt always these values of RelTol and of AbsTol.




Example 6: Kepler equation

The gravitational acceleration given by the Earth to a satellite is

3 2
g r r
r r

= =

(15)

where the symbol

indicates versor , that is r rr =

.
In the formula (15) the vector r

is the radius vector, that is the vector connecting the centre of the
Earth with the center of mass of the satellite and (15) is also called the Keplerian field: it is the
Earth gravitational acceleration in the hypothesis of spherical homogeneous Earth.
The equations of the motion are then:

3
dr
V
dt
dV
r
dt r

=
=

(16)

where the first equation states that the derivative of the position vector is the velocity vector and
second states that the acceleration of the satellite obeys the Kepler law.
We are going to write the system of the 6 differential equations (three for the position and three for
the velocity) in scalar form projecting (16) in the inertial reference frame ( )
1 2 3
, , c c c , see the
following figure.



Let the position coordinates with respect to the inertial reference frame be (X,Y,Z), that is:

1 2 3
r Xc Yc Zc = + +


and let the velocity coordinates with respect to the inertial reference frame be ( ) , ,
X Y Z
V V V , that is:
1 2 3

X Y Z
V V c V c V c = + +


Then the derivative of the vector r

is equal to:

( )
3 1 2
1 2 3 1 2 3


dc dr d dc dc
Xc Yc Zc Xc Yc Zc X Y Z
dt dt dt dt dt
= + + = + + + + +



However the reference frame ( )
1 2 3
, , c c c is inertial, that is the directions of the three versors
( )
1 2 3
, , c c c do not change with time, so
3 1 2

0
dc dc dc
dt dt dt
= = = and

1 2 3
1 2 3


X Y Z
dr
Xc Yc Zc
dt
dr
V V c V c V c
dt
= + +

= = + +


Comparing the two expressions of
dr
dt

we get the three scalar equations:


X
Y
Z
X V
Y V
Z V
=
=
=

(17)
The Keplerian acceleration g

written in the inertial reference frame is:



( )
2 2 2
1 2 3 3 3
, g r Xc Yc Zc r X Y Z
r r

= = + + = + +


On the other hand
1 2 3

X Y Z
dV
V c V c V c
dt
= + +



Hence the second vector equation in (16) becomes:
( )
( )
( )
3/ 2
2 2 2
3/ 2
2 2 2
3/ 2
2 2 2
X
Y
Z
V X
X Y Z
V Y
X Y Z
V Z
X Y Z

=
+ +
=
+ +
=
+ +

(18)

Equations (17) and (18) represent the Kepler equations in the inertial reference frame.

A Keplerian orbit is a solution of the above Kepler equations with a specified initial condition for
the position and the velocity:
0 0 0 0 0 0 0 0
, , , , , ,
X Y Z
r V X Y Z V V V =


Note that the initial conditions
0 0
0
Z
Z V = = correspond to an equatorial orbit, since the vertical
acceleration also will be vanishing (
0 0 3 3
0 0
.0 0
Z
V Z
r r

= = =

) and the initially equatorial orbit will


stay equatorial.
Also for the Kepler equation an integral of the motion exists: namely
( )
( )
2
1/ 2
1 1

2 2
E V V V
r
r r

= =

i

i

In fact the derivative of E gives:
( )
( ) ( )
1/ 2 3/ 2
1 1 1

2 2 2
dE d d dV dV dr dr
V V V V r r
dt dt dt dt dt dt dt
r r r r
| |
| |
= = + + +
| |
\
\




i i i i i

i i

that is

( )
3/ 2 3
dE dV dr dV dr
V r V r
dt dt dt dt r dt
r r
| | | |
| | | |
= + = +
| | | |
\ \
\ \




i i i i

i

Using the equations of motion (13) we get the conservation of the energy :
( )
3/ 2
0 0
dE dV
r V V
dt dt
r r

| |
= + = = |
|
\

i i

i


As an example let us integrate the Kepler equation (17)-(18) with the initial conditions (equatorial
orbit): ( )
0 0 0 0 0 0 0 0
, 100 km, 0, 0, 0, 8 / , 0
E X Y Z
r V X R Y Z V V km s V = = + = = = = =

, using the
numerical program:

%kepler
clear all
close all
global mi RE %mu is the Earth grav. constant and RE the radius of the Earth
Tol=1e-012;
Tol0=1e-09;
RE=6378; % Earth radius in km
mi=398601; % Earth gravitational costant in km^3/s^2
tmax=6000; % integration time (s)
tspan=[0 tmax];
x0=RE+700; % initial conditions
y0=0;
z0=0;
Vx=0;
Vy=8;
Vz=0;
r0=(x0.^2+y0.^2+z0.^2).^0.5; % initial radius
V0=(Vx.^2+Vy.^2+Vz.^2).^0.5; % initial velocity
XX0=[x0 y0 z0 Vx Vy Vz];
options=odeset('RelTol',Tol0,'AbsTol',Tol);
[t,y]=ode45('keplerk',tspan,XX0,options);
X=y(:,1);
Y=y(:,2);
Z=y(:,3);
VX=y(:,4);
VY=y(:,5);
VZ=y(:,6);
LL=length(X);
[XS,YS,ZS]=sphere; % commands to define the Earth surface
XS=XS*RE;
YS=YS*RE;
ZS=ZS*RE;
figure(1)
plot3(X,Y,Z,'k') % plot of the orbit
grid
hold on
surf(XS,YS,ZS)
r=(X.^2+Y.^2+Z.^2).^0.5;
V=(VX.^2+VY.^2+VZ.^2).^0.5;
En=0.5*V.*V-mi./r; % the orbit energy
En0=0.5*V0.*V0-mi./r0; % the initial energy

figure(2) %plot of the three components of the orbit velocity
plot(t,VX,t,VY,t,VZ)
xlabel(time (s))
title(Velocities (km/s))
figure(3)
plot(t,En-En0) % plot of the energy variation
title('Energy(t)-Energy(t0)')
xlabel('time (s)')

% program keplerk
function keplerk=keplerk(t,y)
global mi RE
X=y(1);
Y=y(2);
Z=y(3);
vx=y(4);
vy=y(5);
vz=y(6);
r=sqrt(X^2+Y^2+Z^2);
a1=vx;
a2=vy;
a3=vz;
a4=-mi/r^3*X;
a5=-mi/r^3*Y;
a6=-mi/r^3*Z;
keplerk=[a1 a2 a3 a4 a5 a6]';

The following two figures show the orbit and the orbit together the Earth surface.






The following figure shows the three components of the orbit velocity



The following figure shows the difference between the initial energy and the energy along the orbit.

The orbit that we found is not a circle around the Earth, but rather an ellipse, as it can be noticed
looking at the X,Y plot.



This means that the modulus of the radius is changing in time, that is 0 r r = . To get a circular orbit one
should have constant radius and a constant angular velocity of the satellite around the Earth.
Generally this angular velocity is variable and it can represent the angular velocity

h =

of the
rotation of the frame having the mobile axis r , as in the figure.



r

The transformation between the two reference frames is:


1 1
2 2
3 3

cos sin 0 cos sin 0

sin cos 0 and sin cos 0
0 0 1 0 0 1
r r
c c
c c
c c
h h


| | | |
| | | | | | | |
| |
| | | |
= =
| |
| | | |
| | | | | |
\ \ \ \
\ \

It follows that:
( ) ( )
1 2 1 2

cos sin sin cos


dr dr d
r rr rr r rr r c c rr r c c
dt dt dt
= = + = + + = + +


That is

( ) ( )
1
2

cos sin

sin cos sin cos



sin cos
c r
dr
rr r rr r rr r
c dt
r



| |
| |
= + = + = + |
|
|
+ \
\



Note that

h h r r r rr r = = =



so
dr
r r
dt
= +


This is a general result: the derivative of any vector b

in a reference frame rotating by the angular


velocity

with respect to the inertial frame is equal to the derivative of the vector written in the
rotating frame plus the vector product between the angular velocity

and the vector b

.
Then the acceleration is:

( ) ( )
.
2
2
2
d r
r r r r r r r r
dt

| |
| = + + + = + + +
|
\




and the Kepler equation is in the (orbital) frame
( )

, , r h is:

( )
2
2 r r r r r
r

+ + + =



For a circular orbit we must have 0 r r = = = hence the Kepler equation gives:

( )
2
r r
r

=


That is

2 2
2 2
r r r r
r r

= =


Then the constant angular velocity of a circular orbit of radius
0
r r = is:

3
0
c
r



We have also for circular orbits:

dr
V r r
dt
= = =



Therefore the velocity of a circular orbit is :
0
0

c c
V r
r

= =


The velocity needed to have a circular orbit with altitude 100 km is 7.84 km/s.

The following figure shows the (circular) orbit obtained with 7.84 /
Y
V km s = .


Decreasing the value of
Y
V the orbit will approach the Earth surface, till the impact with the Earth,
see for instance the following picture where 5 /
Y
V km s =

Only a rather small part of the orbit is outside the Earth: most of the trajectory would go through inside the
Earth, passing close the Earth centre.
On the other hand increasing the velocity
Y
V the orbits will be bigger and bigger ellipses around the
Earth till the value
0
2
Y
V
r

= (zero keplerian energy) : with this and higher values of the velocity
the orbit will be non longer closed curves. This means that we have not longer a satellite of the
Earth, but the spacecraft will leave the Earth: the gravitational attraction of the Earth is not longer
able to keep the satellite close to Earth.
The following figure shows the orbit obtained by 11.5 /
Y
V km s =




With such a velocity the spacecraft will leave the Earth along an hyperbolic trajectory.

Potrebbero piacerti anche