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 - 279 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

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

Bild der Seite - 279 -

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

Text der Seite - 279 -

8.6 Exercises 279 Exercise8.15:The LeapfrogMethod We consider the general ODE problemu′(t)= f(u,t),u(0)=U0. To solve such anODEnumerically,thesecondorderLeapfrogmethodapproximatesthederivative (at some time tn=nΔt) byuseofacentereddifferenceover two time steps, u′(tn)≈ u(tn+1)−u(tn−1) 2Δt = u n+1 −un−1 2Δt . a) Replace the derivative in the ODE by the given centered difference approxima- tionandshowthat this allowsus to formulate: un+1 =un−1+2Δtf(un,tn), n=1,2,.. .,Nt −1, withu0 =U0.Dowe have the informationwe need toget theschemestarted? b) Theproblemyoudiscovered in thepreviousquestion,maybefixedbyusing the ForwardEulermethod.However, theLeapfrogmethodisasecondordermethod, while the ForwardEulermethod isfirst order. Argue, with reference to the Taylor series (see, e.g., Exercise 8.14), why the Forward Euler method can be used without reducing the order of the overall scheme. c) ImplementtheLeapfrogschemeinafunctionleapfrog.Makesurethefunction takesanappropriateset of inputparameters, so that it is easy to importanduse. d) Write a function compare_FE_leapfrog that compares graphically the solu- tionsproducedbytheForwardEulerandLeapfrogmethods,whentheysolve the population growth modelu′ = 0.1u, withu(0) = 100. Let the total time span T =20,anduse a time stepdt=2. In the plotproduced, includealso theexact solution, so that thenumerical solutionscanbeassessed. e) Suggest a reasonable asymptotic error model before you write a proper test function test_convergence_rates that may be used to compute and check the convergence rates of the implemented Leapfrog method. However, the test functionshould takeappropriate inputparameters, so that it canbeusedalso for otherODE solvers, in particular theode_FE implementedpreviously. Include your test function in a program, together with the two functions you defined previously (leapfrog and compare_FE_leapfrog). Write the code with a test block, so that it getseasy toeither import functionsfromthe module, or to run it as aprogram. Finally, run theprogram(so thatcompare_FE_leapfroggetscalled,aswell as test_convergence_rates for both FE and Leapfrog) and confirm that it works as expected. In particular, does the plot look good, and do you get the convergenceratesyouexpectedforForwardEulerandLeapfrog? Filename:growth_leapfrog.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