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

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

Image of the Page - 173 -

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

Text of the Page - 173 -

6.8 Exercises 173 Minimization of a function of N variables, E(b1,.. .,bN) is mathematically performedbyrequiringall thepartialderivatives to bezero: βˆ‚E βˆ‚b1 =0, βˆ‚E βˆ‚b2 =0, ... βˆ‚E βˆ‚bN =0 . a) Compute the partial derivative βˆ‚E/βˆ‚b1 and generalize to the arbitrary case βˆ‚E/βˆ‚bn, 1≀n≀N. b) Showthat bn= 1 Ο€ ∫ Ο€ βˆ’Ο€ f(t)sin(nt)dt . c) Write a functionintegrate_coeffs(f, N, M) that computesb1,.. .,bN by numerical integration,usingM intervals in the trapezoidal rule. d) A remarkable property of the trapezoidal rule is that it is exact for inte- grals βˆ«Ο€ βˆ’Ο€ sinntdt (when subintervals are of equal size). Use this property to create a function test_integrate_coeff to verify the implementation of integrate_coeffs. e) Implement the choice f(t) = 1 Ο€ t as a Python function f(t) and call integrate_coeffs(f, 3, 100) to see what the optimal choice ofb1,b2,b3 is. f) Make a function plot_approx(f, N, M, filename)where you plot f(t) together with the best approximationSN as computed above, usingM intervals fornumerical integration.Save theplot toa file withnamefilename. g) Runplot_approx(f, N, M, filename)forf(t)= 1 Ο€ t forN =3,6,12,24. Observehowtheapproximationimproves. h) Run plot_approx forf(t) = eβˆ’(tβˆ’Ο€) andN = 100. Observe a fundamental problem: regardless ofN,SN(βˆ’Ο€)= 0, note2Ο€ β‰ˆ 535. (There are ways to fix this issue.) Filename:autofit_sines.py. Exercise6.13:Derive the TrapezoidalRule foraDouble Integral Use ideas in Sect.6.7.1 to derive a formula for computing a double integral∫b a ∫d c f(x,y)dydxby the trapezoidal rule. Implementand test this rule. Filename:trapezoidal_double.py.
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