Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Page - 260 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 260 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Image of the Page - 260 -

Image of the Page - 260 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Text of the Page - 260 -

260 8 SolvingOrdinaryDifferentialEquations Thefileosc_EC_general.pyhasafunctionEulerCromerthat implementsthis method: def EulerCromer(f, s, F, m, T, U_0, V_0, dt): import numpy as np N_t = int(round(T/dt)) print(’N_t:’, N_t) t = np.linspace(0, N_t*dt, N_t+1) u = np.zeros(N_t+1) v = np.zeros(N_t+1) # Initial condition u[0] = U_0 v[0] = V_0 # 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 The Fourth Order Runge-Kutta Method The RK4 method just evaluates the right-handside of theODEsystem, ( 1 m (F(t)βˆ’s(u)βˆ’f(v)),v) for known values ofu, v, and t, so the method is very simple to use regardless of howthe functionss(u)andf(v)arechosen. 8.4.9 IllustrationofLinearDamping We consider an engineering system with a linear spring, s(u)= kx, and a viscous damper, where the damping force is proportional to uβ€², f(uβ€²) = buβ€², for some constant b > 0. This choice may model the vertical spring system in a car (but engineersoften like to illustrate such a system by a horizontallymovingmass, like the one depicted in Fig. 8.28). We may choose simple values for the constants to illustrate basic effects of damping(and later excitations). Choosing the oscillations to be the simpleu(t) = cost function in the undamped case, we may setm = 1, k = 1, b = 0.3, U0 = 1, V0 = 0. The following function implements this case: def linear_damping(): import numpy as np b = 0.3 f = lambda v: b*v s = lambda u: k*u F = lambda t: 0 m = 1 k = 1
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python 3.6
Volume
Second Edition
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2020
Language
English
License
CC BY 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
356
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python