Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Seite - 102 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 102 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Bild der Seite - 102 -

Bild der Seite - 102 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Text der Seite - 102 -

102 4 FunctionsandtheWritingofCode argumentf is a Python function forf(t) andN is the number of termsN in the sumSN(t).Thetrial functioncanruna loopwhere theuser isaskedfor thebn values in each pass of the loop and the corresponding plot is shown. You must find a way to terminate the loop when the experiments are over. UseM=500 in thecalls toplot_compareanderror. f) Choosef(t) tobeastraight linef(t)= 1 π t on [−π,π].Calltrial(f, 3)and try tofind throughexperimentationsomevaluesb1,b2, andb3 such that thesum ofsinesSN(t) is a goodapproximationto thestraight line. g) Now we shall try to automate the procedure in f). Write a function that has threenested loopsovervaluesofb1,b2, andb3. Let each loopcover the interval [−1,1] in steps of 0.1. For each combination ofb1, b2, andb3, the error in the approximationSN should be computed. Use this to find, and print, the smallest errorand thecorrespondingvaluesofb1,b2, andb3.Let theprogramalsoplotf and theapproximationSN correspondingto thesmallest error. Filename:fit_sines.py. Remarks 1. The functionSN(x) is a special case of what is called a Fourier series. At the beginning of the nineteenth century, Joseph Fourier (1768–1830) showed that any function can be approximated analytically by a sum of cosines and sines. The approximation improves as the number of terms (N) is increased. Fourier series arevery important throughoutscienceandengineering today. (a) Finding thecoefficientsbn is solvedmuchmoreaccurately inExercise6.12, byaprocedure thatalso requiresmuch less humanandcomputerwork! (b) Inrealapplications,f(t) isnotknownasacontinuousfunction,but function values of f(t) are provided. For example, in digital sound applications, music in a CD-quality WAV file is a signal with 44,100 samples of the correspondinganalogsignalf(t)per second. Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation,distributionandreproduction inanymediumor format, as longasyougiveappropriate credit to theoriginal author(s) and thesource, provide a link to theCreative Commons licenceand indicate ifchanges were made. The images or other third party material in this chapter are included in the chapter’s Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the chapter’s Creative Commons licence and your intended use is not permitted by statutory regulation orexceeds thepermitted use, you willneed toobtain permission directly from thecopyright holder.
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python 3.6
Band
Second Edition
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2020
Sprache
englisch
Lizenz
CC BY 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
356
Schlagwörter
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Kategorie
Informatik
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python