Applied Physics 461b/861b

COMPUTATIONAL PHYSICS

Assignment 1

due Wednesday, January 22, 1997

1. Introduction to Fortran

Write, compile and run a Fortran program that reads in pairs (possibly more than one) of real numbers from a file, subtracts them, and writes an ``informative'' output to another file. Do this both in single and in double precision. Find out what happens when you give as input a number of significant figures that exceeds the capacity of the precision. Find out what happens when the two input numbers are almost equal, and comment.

2. Introduction to Mathematica

Mathematica is particularly useful for operations such as differentiation and series expansion of simple functions, fitting to polynomials, plotting functions of one and two variables, and solving simple sets of equations analytically or numerically. Create a Mathematica notebook which does the following:
  1. define f(x) = 1 - 2 x^2 + 3 x^4 + 4 x^6 (note: you can choose to do this either as an algebraic expression f = 1 - 2 x^2 + 3 x^4 + 4 x^6 or a function definition f[x_]:=1 - 2 x^2 + 3 x^4 + 4 x^6);
  2. evaluate f(x) at x=0, x=1 and x=2;
  3. plot f(x) from x=-1 to x=1;
  4. find the extremum points of f(x) and minimum value of f;
  5. fit a + b x^2 + c x^4 + d x^6 to the following set of points, (0.2,0.93), (0.3,0.85), (0.4,0.77), (0.5,0.75), (0.6,0.86), (0.7,1.2), (0.8,2.0) and plot the fit and the points together for comparison;
  6. compute the first few terms in the Taylor series of V(r) = ((1-e^(-2(r-0.5))^2-1) around r=0.5, and plot the function and the approximation given by the first two, three and four terms together for comparison (note: this is called the Morse potential and is a useful analytical approximation to the potential of a diatomic molecule).

3. Determining machine epsilon

Working on mercury, write a fortran program which estimates machine epsilon (in single precision) by finding the smallest number which, when added to 1, gives a result different from 1. Rerun the program in double precision and compare the answers. Enclose a printout of the program with appropriate comments.