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

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

Image of the Page - 282 -

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

Text of the Page - 282 -

282 8 SolvingOrdinaryDifferentialEquations Exercise8.18:The Three-StepAdams-BashforthMethod ThisexercisebuildsonExercise8.17,soyoubetterdothatonefirst.Anothermulti- stepmethod,is the three-stepAdams-Bashforthmethod.This isa thirdordermethod witha computationalscheme that reads: un+1 =un+Ξ”t 12 ( 23f(un,tn)βˆ’16f(unβˆ’1,tnβˆ’1)+5f(unβˆ’2,tnβˆ’2) ) . forn=2,3,.. .,Nt βˆ’1,withu0 =U0. a) Assumethat someoneimplemented theschemeas follows: def adams_bashforth_3(f, U_0, dt, T): """Third-order Adams-Bashforth scheme for solving first order ODE""" N_t = int(round(T/dt)) u = np.zeros(N_t+1) t = np.linspace(0, N_t*dt, len(u)) u[0] = U_0 # Compute missing starting values u[1] = 100*np.exp(0.1*dt) u[2] = 100*np.exp(0.1*(2*dt)) for n in range(1, N_t, 1): u[n+1] = u[n] + (dt/12)*(23*f(u[n], t[n]) - \ 16*f(u[n-1], t[n-1]) +\ 5*f(u[n-2], t[n-2])) return u, t There is one (known!)bug here,find it! Try first by simply reading the code. If not successful,youmaytry to run it anddosometesting onyourcomputer. Also, what would you say about the way that missing starting values are computed? b) RepeatExercise8.17,using thegiven three-stepmethod in steadof the two-step method. Note that with the three-step method, you need 3 starting values. Use the Runge-Kutta third order scheme for this purpose. However, check also the convergencerate of theschemewhenmissingstartingvaluesarecomputedwith ForwardEuler in stead. Filename:Adams_Bashforth_3.py. Exercise8.19:Use aBackwardEuler SchemeforOscillations Consider(8.43)–(8.44)modelinganoscillatingengineeringsystem.This2Γ—2ODE systemcanbesolvedbytheBackwardEulerscheme,which isbasedondiscretizing derivatives by collecting information backward in time. More specifically,uβ€²(t) is approximatedas uβ€²(t)β‰ˆ u(t)βˆ’u(tβˆ’Ξ”t) Ξ”t .
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