Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Page - 105 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 105 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Image of the Page - 105 -

Image of the Page - 105 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text of the Page - 105 -

4.1 PopulationGrowth 105 4.1.4 UnderstandingtheForwardEulerMethod The good thing about the ForwardEulermethod is that it gives an understanding ofwhat a differential equation is andageometrical picture ofhowto construct the solution. The first idea is thatwe have already computed the solution up to some time point tn. The second idea is thatwewant to progress the solution from tn to tnC1 asa straight line. Weknowthat the linemust go through the solutionat tn, i.e., thepoint .tn;un/. The differential equation tells us the slope of the line: u0.tn/ D f.un;tn/ D run. That is, the differential equation gives a direct formula for the furtherdirection of the solution curve. We can say that the differential equation expresses how the system(u)undergoeschangesat apoint. There is ageneral formula fora straight lineyDaxCbwith slopea thatgoes through thepoint .x0;y0/:yDa.x x0/Cy0. Using this formulaadapted to the present case, andevaluating the formulafor tnC1, results in unC1 D run.tnC1 tn/Cun DunC trun; which isnothingbut theForwardEuler formula.YouarenowencouragedtodoEx- ercise4.1 tobecomemorefamiliarwith thegeometric interpretationof theForward Eulermethod. 4.1.5 ProgrammingtheForwardEulerScheme;theGeneralCase Ourpreviousprogramwas just aflatmainprogramtailored toa specialdifferential equation.Whenprogrammingmathematics, it is alwaysgood to consider a (large) class of problemsandmakingaPython function to solveanyproblemthatfits into the class. More specifically, we will make software for the class of differential equationproblemsof the form u0.t/Df.u;t/; uDU0; t 2 Ε’0;T ; for somegiven functionf , and numbersU0 andT . We also take the opportunity to illustrate what is commonly called a demo function. As the name implies, the purpose of such a function is solely to demonstrate how the functionworks (not to be confused with a test function, which does verification by use of assert). The Python function calculating the solutionmust take f ,U0, t, and T as in- put, find the correspondingNt, compute the solution, and return an array with u0;u1;:: :;uNt andanarraywith t0;t1;: : :;tNt . TheForwardEuler schemereads unC1 DunC tf.un;tn/; nD0;:: :;Nt 1: Thecorrespondingprogrammaynowtake the form(fileode_FE.py):
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2016
Language
English
License
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
248
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