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 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 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 Riemann sums, the trapezoidal rule, and Simpson's rule. Other, more sophisticated schemes exist, including Gaussian quadrature. Mathematica uses a series of methods, including various forms of quadrature, to perform precise numerical integration.

Good programming practise

  • One heuristic: Make it easily understandable to anyone who reads it. Don't panic about efficiency.

Numerical Recipes

 
20.2.txt · Last modified: 2011/10/06 14:10 by hchu
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki