====== Physics 20 Reading List for Week 2 ====== This week's reading is rather low key. First, most if not all of the information you need is in the assignment text. Failing that, a keyword search on wikipedia is a good start. ===== Python and functions ===== Most of you have already started using functions in Python. For those of you who haven't, this week's set requires you to. To learn about functions, ask a friend, work it out yourself, or refer to Guido van Rossum's [[http://docs.python.org/tutorial/controlflow.html#defining-functions|Python Tutorial]]. Pay attention in particular at how functions are primitive objects in Python (in fact, everything is an object in Python). Thus, we could define a function evalinzero(f) which returns the value of another function for x = 0: def evalinzero(f): return f(0) we then have import math evalinzero(math.exp) 1.0 which works also for home-grown functions, def xplusone(x): return x+1.0 evalinzero(xplusone) 1.0 and even for [[http://en.wikipedia.org/wiki/Lambda_calculus|lambda functions]], evalinzero(lambda x: x+1.0) 1.0 It should now be reasonably straight forward how functions work in Python. Similar to C, Fortran, Mathematica, Matlab, etc, though the syntax varies a bit. ===== Numerical Integration ===== Have a look at [[http://en.wikipedia.org/wiki/Riemann_sum|Riemann sums]], the [[http://en.wikipedia.org/wiki/Trapezoidal_rule|trapezoidal rule]], and [[http://en.wikipedia.org/wiki/Simpson%27s_rule|Simpson's rule]]. Other, more sophisticated schemes exist, including [[http://en.wikipedia.org/wiki/Gaussian_quadrature|Gaussian quadrature]]. Mathematica uses a series of methods, including various forms of quadrature, to perform precise numerical integration. ===== Good programming practise ===== * A humorous piece, full of good advice, by Spanish computer scientist A. Cernuda del Río: [[http://dl.acm.org/citation.cfm?doid=1024338.1024381|``How Not to Go About a Programming Assignment,'']] SIGCSE Bulletin 36, 97 (2004). * One heuristic: Make it easily understandable to anyone who reads it. Don't panic about efficiency. [[http://www.google.com/url?sa=t&source=web&cd=5&ved=0CDYQFjAE&url=http%3A%2F%2Fastronu.jinr.ru%2Fwiki%2Fupload%2Fd%2Fd6%2FNumericalRecipesinC.pdf&rct=j&q=Eq.%204.1.13%20of%20Numerical%20Recipes&ei=1xiOTsaWLsWPsQLe9ozRAQ&usg=AFQjCNGODbd4blFznuPT24M9bKJHOMcJBw&sig2=j9YSoymiS_tC_wLjnX0H8A&cad=rja|Numerical Recipes]]