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

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

Image of the Page - 171 -

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

Text of the Page - 171 -

6.8 Exercises 171 Hint Edittest_trapezoidal.py. Filename:rectangle_methods.py. Exercise6.9:AdaptiveIntegration Supposewe want to use the trapezoidalormidpointmethod to computean integral∫b a f(x)dxwith an error less than a prescribed tolerance . What is the appropriate sizeofn? Toanswer thisquestion,we mayenteran iterativeprocedurewherewe compare the results produced byn and 2n intervals, and if the difference is smaller than , the value corresponding to 2n is returned. Otherwise, we halve n and repeat the procedure. Hint It may be a good idea to organize your code so that the function adaptive_integrationcanbeusedeasily in futureprogramsyouwrite. a) Write a function adaptive_integration(f, a, b, eps, method=midpoint) that implements the idea above (eps corresponds to the tolerance , and method canbemidpointortrapezoidal). b) Test themethodon ∫2 0 x 2dx and ∫2 0 √ xdx for =10βˆ’1,10βˆ’10 andwriteout the exacterror. c) Make a plot ofnversus ∈ [10βˆ’1,10βˆ’10] for∫20 √ xdx. Use logarithmicscale for . Filename:adaptive_integration.py. Remarks The typeofmethodexplored in this exercise is called adaptive, because it tries toadapt thevalueofn tomeetagivenerrorcriterion.Thetrueerrorcanvery seldom be computed (since we do not know the exact answer to the computational problem),soonehas tofindother indicatorsof theerror,suchas theoneherewhere the changes in the integral value, as the number of intervals is doubled, is taken to reflect theerror. Exercise6.10:Integratingx Raisedtox Consider the integral I = ∫ 4 0 xxdx. The integrandxx doesnot have an anti-derivative that can be expressed in termsof standard functions (visit http://wolframalpha.comand typeintegral(x**x,x) to convinceyourself that ourclaimis right.Note thatWolframalphadoesgiveyouan answer,but thatanswerisanapproximation,it isnotexact.This isbecauseWolfram alpha too uses numerical methods to arrive at the answer, just as you will in this
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