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

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

Image of the Page - 280 -

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

Text of the Page - 280 -

280 8 SolvingOrdinaryDifferentialEquations Exercise8.16:The Runge-KuttaThird OrderMethod AgeneralODEproblemu′(t)=f(u,t),u(0)=U0,maybesolvednumericallyby the thirdorderRunge-Kuttamethod.Thecomputationalschemereads un+1 =un+Δt 6 (k1+4k2+k3) , n=0,1,.. .,Nt −1, k1 =f(un,tn), k2 =f(un+Δt 2 ,tn+Δt 2 ), k3 =f(un−Δtk1+2Δtk2,tn+Δt), withu0 =U0. a) Implement the scheme in a functionRK3 that takes appropriate parameters, so that it is easy to importandusewheneverneeded. b) Write a functioncompare_FE_RK3 that comparesgraphically the solutionspro- duced by the Forward Euler and RK3 methods, when they solve the population growthmodelu′ = 0.1u,withu(0)= 100. Let the total time spanT = 20, and use a time stepdt = 2. In the plot produced, include also the exact solution, so that the numericalsolutionscanbeassessed. c) Suggest a reasonable asymptotic error model before you write a proper test functiontest_convergence_ratesthatmaybeusedtocomputeandcheckthe convergence rates of the implemented RK3 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 function). Include your test function in a program, together with the two functions you definedpreviously(RK3andcompare_FE_RK3).Writethecodewithatestblock, so that it gets easy to either import functions from the module, or to run it as a program. Finally, run the program (so that compare_FE_RK3 gets called, as well as test_convergence_ratesfor bothFE andRK3) andconfirmthat it worksas expected. In particular,does the plot look good,anddo youget the convergence ratesyouexpectedforForwardEulerandRK3? Filename:runge_kutta_3.py. Exercise8.17:The Two-StepAdams-BashforthMethod Differingfromthe single-stepmethodspresented in thischapter,wehave themulti- step methods, for example the Adams-Bashforth methods. With the single-step methods, un+1 is computed by use of the solution from the previous time step, i.e.un. In multi-step methods, the computed solutions from several previous time steps, e.g., un, un−1 and un−2 are used to estimate un+1. How many time steps that are involved in the computing of un+1, and how the previous solutions are
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