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

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

Image of the Page - 92 -

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

Text of the Page - 92 -

92 3 Computing Integrals MinimizationofafunctionofN variables,E.b1;:: :;bN/ ismathematicallyper- formedby requiringall thepartial derivatives tobezero: @E @b1 D0; @E @b2 D0; ::: @E @bN D0: a) Compute the partial derivative @E=@b1 and generalize to the arbitrary case @E=@bn,1 n N . b) Showthat bn D 1 Z 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 integralsR 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/ D 1 t as a Python function f(t) and call inte- grate_coeffs(f, 3, 100) to seewhat theoptimalchoiceofb1;b2;b3 is. f) Make a function plot_approx(f, N, M, filename)where you plot f(t) togetherwith thebest approximationSN ascomputedabove,usingM intervals fornumerical integration. Save theplot toafilewithnamefilename. g) Runplot_approx(f, N, M, filename)forf.t/D 1 t forN D3;6;12;24. Observehowtheapproximation improves. h) Runplot_approx forf.t/ D e .t / andN D 100. Observe a fundamental problem: regardlessofN ,SN. /D0, note2 535. (Thereareways tofix this issue.) Filename:autofit_sines.py. Exercise3.13:Derive the trapezoidalrule foradouble integral Use ideas in Sect. 3.7.1 to derive a formula for computing a double integralRb a Rd c f.x;y/dydx by the trapezoidal rule. Implementand test this rule. Filename:trapezoidal_double.py. Exercise3.14:Compute theareaofa trianglebyMonteCarlo integration UsetheMonteCarlomethodfromSect.3.7.3 tocompute theareaofa trianglewith verticesat . 1;0/, .1;0/, and .3;0/. Filename:MC_triangle.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