Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Seite - 276 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 276 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Bild der Seite - 276 -

Bild der Seite - 276 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Text der Seite - 276 -

276 8 SolvingOrdinaryDifferentialEquations values,modifytheprogramosc_FE.py todumptheuarraytofile, runosc_FE.py, and let the test functionread the referenceresults fromthatfile. Filename:osc_ode_FE.py. Exercise8.11:Compute the Energy in Oscillations a) Make a function osc_energy(u, v, omega) for returning the potential and kineticenergyofanoscillatingsystemdescribedby(8.43)–(8.44).Thepotential energy is taken as 12ω 2u2 while the kinetic energy is 12v 2. (Note that these expressionsare notexactly thephysicalpotential andkineticenergy,since these wouldbe 12mv 2 and 12ku 2 fora modelmx′′+kx=0.) Place the osc_energy in a separate file osc_energy.py such that the functioncanbecalled fromother functions. b) Addacall toosc_energy in theprogramsosc_FE.pyandosc_EC.pyandplot the sum of the kinetic and potential energy. How does the total energy develop for theForwardEulerand theEuler-Cromerschemes? Filenames:osc_energy.py,osc_FE_energy.py,osc_EC_energy.py. Exercise8.12:Use aBackwardEuler SchemeforPopulationGrowth We consider the ODE problem N′(t) = rN(t), N(0) = N0. At some time, tn = nΔt, we can approximate the derivative N′(tn) by a backward difference, seeFig. 8.22: N′(tn)≈ N(tn)−N(tn−Δt) Δt = N n−Nn−1 Δt , which leads to Nn−Nn−1 Δt = rNn, called theBackwardEuler scheme. a) Find an expression for theNn in terms ofNn−1 and formulate an algorithm for computingNn,n=1,2,.. .,Nt. b) Implement the algorithm in a) in a function growth_BE(N_0, dt, T) for solvingN′ = rN,N(0)=N0, t∈ (0,T],with time stepΔt (dt). c) Implement the Forward Euler scheme in a functiongrowth_FE(N_0, dt, T) asdescribed inb). d) Compare visually the solution produced by the Forward and Backward Euler schemes with the exact solution when r = 1 andT = 6. Make two plots, one withΔt=0.5andonewithΔt=0.05. Filename:growth_BE.py.
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python 3.6
Band
Second Edition
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2020
Sprache
englisch
Lizenz
CC BY 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
356
Schlagwörter
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Kategorie
Informatik
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python