Page - 144 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python
Image of the Page - 144 -
Text of the Page - 144 -
144 4 SolvingOrdinaryDifferentialEquations
# Step equations forward in time
for n in range(N_t):
v[n+1] = v[n] + dt*(1./m)*(F(t[n]) - f(v[n]) - s(u[n]))
u[n+1] = u[n] + dt*v[n+1]
return u, v, t
The4-th orderRunge-Kuttamethod TheRK4method just evaluates the right-
handsideof theODEsystem,
. 1
m .F.t/ s.u/ f.v//;v/
for knownvalues ofu,v, and t, so themethod is very simple to use regardless of
howthe functionss.u/andf.v/arechosen.
4.3.9 IllustrationofLinearDamping
Weconsider anengineering systemwith a linear spring, s.u/Dkx, andaviscous
damper, where the damping force is proportional to u0, f.u0/ D bu0, for some
constant b > 0. This choicemaymodel the vertical spring system in a car (but
engineers often like to illustrate such a system by a horizontalmovingmass like
the one depicted in Fig. 4.25). Wemay choose simple values for the constants to
illustratebasiceffectsofdamping(and later excitations). Choosing theoscillations
to be the simpleu.t/ D cost function in the undampedcase,wemay setm D 1,
kD1,bD0:3,U0 D1,V0 D0. The followingfunction implements this case:
def linear_damping():
b = 0.3
f = lambda v: b*v
s = lambda u: k*u
F = lambda t: 0
m = 1
k = 1
U_0 = 1
V_0 = 0
T = 12*pi
dt = T/5000.
u, v, t = EulerCromer(f=f, s=s, F=F, m=m, T=T,
U_0=U_0, V_0=V_0, dt=dt)
plot_u(u, t)
Theplot_u function is a collection of plot statements for plottingu.t/, or a part
of it. Figure 4.27 shows the effect of the bu0 term: we have oscillationswith (an
approximate)period2 , as expected,but theamplitude is efficientlydamped.
Remarkaboutworkingwithascaledproblem
Instead of settingb D 0:3 andm D k D U0 D 1 as fairly βunlikelyβ physical
values, itwouldbebetter toscale theequationmu00Cbu0CkuD0. Thismeans
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