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

Seite - 12 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Bild der Seite - 12 -

Bild der Seite - 12 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text der Seite - 12 -

12 1 TheFirstFewSteps 1.5 MoreBasicConcepts Sofarwehaveseena fewbasicexamplesonhowtoapplyPythonprogrammingto solvemathematical problems. Beforewe can go onwith other andmore realistic examples, we need to briefly treat some topics thatwill be frequently required in later chapters. These topics include computer science concepts like variables, ob- jects, errormessages, andwarnings;morenumericalconcepts like roundingerrors, arithmetic operator precedence, and integer division; in addition to more Python functionalitywhenworkingwitharrays,plotting, andprinting. 1.5.1 UsingPythonInteractively Python can also be used interactively. That is, we do not first write a program in a file and execute it, butwe give statements and expressions towhat is known as a Python shell. We recommend to use IPython as shell (because it is superior to alternativePythonshells).WithSpyder,Ipython is availableat startup, appearing as the lower right window. Following the IPython prompt In [1]: ( a prompt meansa“readysign”, i.e. theprogramallowsyoutoenteracommand,anddifferent programsoftenhavedifferent lookingprompts),youmaydocalculations: In [1]: 2+2 Out [1]: 4 In [2]: 2*3 Out [2]: 6 In [3]: 10/2 Out [3]: 5 In [4]: 2**3 Out [4]: 8 The response fromIPython is precededbyOut [q]:,whereqequalspwhen the response is to input “number”p. Note that, as in a program, youmay have to use import before using pi or functions likesin,cos, etc. That is, at the prompt, do the commandfrom math import *beforeyouusepiorsin, etc. Importingothermodules thanmathmay berelevant,dependingonwhatyouraim iswith thecomputations. Youmayalsodefinevariablesanduse formulas interactivelyas In [1]: v0 = 5 In [2]: g = 9.81 In [3]: t = 0.6 In [4]: y = v0*t - 0.5*g*t**2 In [5]: print y ------> print(y) 1.2342
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2016
Sprache
englisch
Lizenz
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
248
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