Tuesday, October 19, 2004

Physics 20 Reading List for the week of 10/18-10/22/2004

This week you will be reading about the integrating powers of Mathematica, about defining functions and passing them as arguments in Python, and about the basics of numerical integration.

1. Mathematica and integration

In the introduction to this week's assignment I mention Mathematica's Integrate[] function (see secs. 3.5.6--3.5.8 of the Mathematica manual) and its numerical cousin NIntegrate[]. Mathematica contains a very powerful algorithm to perform integrals analytically; so powerful, in fact, that Wolfram decided to show it off by allowing free web access to the Integrate[] function. While you're visiting that site, have a look at its brief history of integration, and at its description of the algorithm used internally by Mathematica. Also, learn a bit more about the Risch algorithm.

2. Python and functions

To complete this week's assignment you need to know about Python functions: read about them in your favorite Python manual, in Guido van Rossum's Python Tutorial, in How to Think Like a Computer Scientist, or in the Python Grimoire.

Make 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


3. Numerical integration

After reading the introduction to numerical integration in this week's assignment, have a look at Secs. 4.0 and 4.1 in Numerical Recipes in C (we also have several copies of this book in the lab).

If you wish to try your hand at the final, optional item in the assignment, read also Sec. 4.3 on Romberg Integration.

0 Comments:

Post a Comment

<< Home