Professional Documents
Culture Documents
Overview
Physical models results often in differential equations which needed to be solved
(e.g. Newton, Maxwell, Schroedinger)
Analytical solutions available only in very simple cases
We will cover in this chapter basic numerical solutions to some general problems:
- only focus on ODEs (Ordinary Differential Equations: one variable and linear)
- PDEs (Partial Differential Equations: multiple variables and linear) will be
treated later
The numerical solutions will be compared with analytical models in some simple
examples error estimation
We will use C++ to compute the ODEs, and Python to show the result (i.e. the
plot)
Analytic Geometry
2 / 11
Analytic Geometry
3 / 11
Analytic Geometry
4 / 11
dr
= v.
dt
The acceleration a can depend on the position r and the velocity v. In case of
Newtonian mechanics, the acceleration of a body with mass m is given by:
a(r, v) =
1
Ft (r, v),
m
where Ft is the total force acting on the the body with mass m.
For complicated forces, an analytical formula is not available and a numerical
method is imposed to solve the problem. Therefore we need to model the
first-order derivatives w.r.t. time.
Analytic Geometry
5 / 11
Forward derivative
In order to solve such equations numerically, one needs to discretize the (first
order) derivatives. By definition ( is a parameter),
f (t + ) f (t)
.
f 0 (t) =
f (t + ) f (t)
+ O( ).
The first term is an approximation of the derivative (called the forward derivative)
and the error associated is linear in (i.e. the larger , the larger the error).
We cannot make arbitrary small, due to round-off effects when using floating
point numbers. Typical limitations are in the order of 108 . In general, the
size of must be deduced based on the scale of the problem. A good
approximation is using a time scale lower than the scale which makes the problem
almost linear.
Jan Eysermans (BUAP)
Analytic Geometry
6 / 11
Euler method
We can use the forward derivative formula to solve our (general) equations of
motion. After some algebra one obtains:
v(t + ) = v(t) + a(r(t), v(t)) + O( 2 ),
r(t + ) = r(t) + v(t) + O( 2 ).
Dropping the second order terms and changing notation, one becomes the
(discrete) Euler method equations:
vn+1 = vn + an ,
rn+1 = rn + vn .
Keep in mind that the error in both position and velocity is O( 2 ).
Analytic Geometry
7 / 11
Analytic Geometry
8 / 11
Implementation in C++
The following general scheme can be used to obtain a numerical solution of the
trajectory:
1. Specify the initial conditions (r1 , v1 );
2. Choose a time step ;
3. Calculate the acceleration a(r, v);
4. Update the value for r and v (Euler, Euler-Cromer, midpoint);
5. Go again to step 3 or break if the amount of points has been reached.
The physical model determining the trajectory is stored in the function a(r, v).
Analytic Geometry
9 / 11
Analytic Geometry
10 / 11
Analytic Geometry
11 / 11