Page - 143 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python
Image of the Page - 143 -
Text of the Page - 143 -
4.3 OscillatingOne-DimensionalSystems 143
Anymethod for a systemoffirst-orderODEscanbeused to solve foru.t/ and
v.t/.
The Euler-Cromer scheme An attractive choice from an implementational, ac-
curacy, and efficiency point of view is the Euler-Cromer schemewhere we take
a forwarddifference in (4.68)andabackwarddifference in (4.69):
vnC1 vn
t D 1
m .F.tn/ s.un/ f.vn//; (4.70)
unC1 un
t DvnC1; (4.71)
Wecaneasily solve for thenewunknownsvnC1 andunC1:
vnC1 DvnC t
m .F.tn/ s.un/ f.vn//; (4.72)
unC1 DunC tvnC1 : (4.73)
RemarkontheorderingoftheODEs
The ordering of the ODEs in the ODE system is important for the extended
model (4.68)β(4.69). Imagine thatwewrite theequationforu0first and then the
one forv0. TheEuler-Cromermethodwould thenfirst use a forwarddifference
for unC1 and then a backward difference for vnC1. The latter would lead to
anonlinearalgebraicequation forvnC1,
vnC1C t
m f.vnC1/DvnC t
m F.tnC1/ s.unC1/ ;
iff.v/ is anonlinear functionofv. Thiswould requireanumericalmethod for
nonlinear algebraic equations to find vnC1, while updatingvnC1 through a for-
ward difference gives an equation forvnC1 that is linear and trivial to solve by
hand.
Thefileosc_EC_general.pyhasafunctionEulerCromerthat implementsthis
method:
def EulerCromer(f, s, F, m, T, U_0, V_0, dt):
from numpy import zeros, linspace
N_t = int(round(T/dt))
print βN_t:β, N_t
t = linspace(0, N_t*dt, N_t+1)
u = zeros(N_t+1)
v = zeros(N_t+1)
# Initial condition
u[0] = U_0
v[0] = V_0
back to the
book Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations β Python
A Gentle Introduction to Numerical Simulations with Python
- Title
- Programming for Computations β Python
- Subtitle
- A Gentle Introduction to Numerical Simulations with Python
- Authors
- Svein Linge
- Hans Petter Langtangen
- Publisher
- Springer Open
- Date
- 2016
- Language
- English
- License
- CC BY-NC 4.0
- ISBN
- 978-3-319-32428-9
- Size
- 17.8 x 25.4 cm
- Pages
- 248
- Keywords
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Category
- Informatik