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

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

Bild der Seite - 281 -

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

Text der Seite - 281 -

8.6 Exercises 281 combined, depends on the method.11 With multi-step methods, more than one startingvalueis requiredtoget theschemestarted.Thus,apart fromthegiveninitial condition, the remaining starting values must be computed. This is done by some other appropriate scheme (in such a way that the convergence rate of the overall schemeisnot reduced). Note that the Runge-Kutta methods are single-step methods, even if they use several intermediate steps (between tn and tn+1) when computingun+1, using no otherprevioussolution thanun. One of the simplest multi-step methods is the (second order) two-step Adams- Bashforthmethod.Thecomputationalschemereads: un+1 =un+Δt 2 ( 3f(un,tn)−f(un−1,tn−1) ) , forn=1,2,.. .,Nt −1,withu0 =U0. a) Implementtheschemeinafunctionadams_bashforth_2that takesappropriate parameters, so that it is easy to importanduse wheneverneeded.Use aForward Euler schemeto compute the missingstartingvalue. b) Write a function compare_FE_AdamsBashforth2 that compares graphically the solutions produced by the Forward Euler and two-step Adams-Bashforth methods, when they solve the population growth model u′ = 0.1u, with u(0) = 100. Let the total time span T = 20, and use a time step dt = 2. In the plot produced, include also the exact solution, so that the numerical solutionscanbeassessed. c) Suggest a reasonable asymptotic error model before you write a proper test function test_convergence_rates that may be used to com- pute and check the convergence rates of the implemented AB2 method. However, the test function should take appropriate input parameters, so that it can be used also for other ODE solvers, in particular the ode_FE implemented previously (if you already have written this test function when doing Exercise 8.15, you may prefer to import the func- tion). Include your test function in a program, together with the two functions you defined previously (AB2andcompare_FE_AdamsBashforth2). Write the code with a test block, so that it getseasy toeither import functionsfromthe module, or to run it as aprogram. Finally, run the program (so that compare_FE_AdamsBashforth2 gets called, as well as test_convergence_rates for both FE and AB2) and confirm that it works as expected. In particular, does the plot look good, and do you get the convergence rates you expected for Forward Euler and AB2? Filename:Adams_Bashforth_2.py. 11 Read more about multi-step methods, e.g., on Wikipedia (https://en.wikipedia.org/wiki/Linear_ multistep_method).
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