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 - 281 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

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

Image of the Page - 281 -

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

Text of the Page - 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).
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