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

Seite - 156 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Bild der Seite - 156 -

Bild der Seite - 156 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text der Seite - 156 -

156 4 SolvingOrdinaryDifferentialEquations Exercise4.11:UseaBackwardEuler schemeforpopulationgrowth We consider the ODE problemN 0.t/ D rN.t/, N.0/ D N0. At some time, tn D n t, we can approximate the derivativeN 0.tn/ by a backward difference, seeFig. 4.19: N 0.tn/ N.tn/ N.tn t/ t D N n Nn 1 t ; which leads to Nn Nn 1 t D rNn; called theBackwardEuler scheme. a) Findanexpression for theNn in termsofNn 1 andformulateanalgorithmfor computingNn,nD1;2;:: :;Nt. b) Implementthealgorithmina) inafunctiongrowth_BE(N_0, dt, T) forsolv- ingN 0 D rN ,N.0/DN0, t 2 .0;T ,with timestep t (dt). c) Implement theForwardEuler scheme ina functiongrowth_FE(N_0, dt, T) asdescribed inb). d) Compare visually the solution produced by the Forward and Backward Euler schemeswith the exact solutionwhen r D 1 andT D 6. Make twoplots, one with t D0:5andonewith t D0:05. Filename:growth_BE.py. Exercise4.12:UseaCrank-Nicolsonschemeforpopulationgrowth It is recommendedtodoExercise4.11prior to thepresentone.Herewe lookat the same population growthmodelN 0.t/ D rN.t/,N.0/ D N0. The time derivative N 0.t/ can be approximated by various types of finite differences. Exercise 4.11 considersabackwarddifference(Fig.4.19),whileSect.4.1.2explainedtheforward difference (Fig. 4.2). A centered difference is more accurate than a backward or forwarddifference: N 0.tnC 1 2 t/ N.tnC t/ N.tn/ t D N nC1 Nn t : This typeofdifference,appliedat thepoint tnC12 D tnC 1 2 t, is illustratedgeomet- rically inFig. 4.20. a) Insert the finite difference approximation in theODEN 0 D rN and solve for the unknownNnC1, assumingNn is already computed andhence known. The resultingcomputationalschemeisoftenreferredtoasaCrank-Nicolsonscheme. b) Implementthealgorithmina) inafunctiongrowth_CN(N_0, dt, T) forsolv- ingN 0 D rN ,N.0/DN0, t 2 .0;T ,with timestep t (dt).
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2016
Sprache
englisch
Lizenz
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
248
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