*PHY201 Physics Computations*

*Teaching Fortran to Physics Majors*

Aleksandar Donev, Dr.
Phillip Duxbury

Michigan State University, December 2000

This webpage contains sample worksheets for a model
course in computational
physics that attempts to teach physics majors Fortran 90/95. In a somewhat
modified form, these have been used in an actual PHY201
course at MSU during Fall 2000. These worksheets are by no means complete,
and there are significant gaps in the coverage. You can find the Fortran
manual that accompanied the course in various formats here, but please
understand that these worksheets were written after the manual and so there
are some discrepancies (and errors in the manual in general). Also, the
manual starts with a coverage of FORTRAN 77, which is avoided carefully
in these worksheets.

*These worksheets and solutions work with the VAST
Fortran 90 compiler, which did require minor modifications from the
``best'' Fortran 90 at times. Many thanks to VAST for providing us with
the compiler!!!*

**Worksheet 1: ***Introduction*

*The way students are introduced to this material should vary greatly
depending on the students' backgrounds. The worksheets that follow are
*__not
an introduction__ to computation. Experience with programming is assumed,
such as the PHY102
course. Some students found the course easy, some challenging, some
difficult. We see no easy fix for this one. So put any worksheet(s) here
that you deem appropriate.

**...**

**The Error function**

*This next series of worksheets deals with the calculation of the
error function using Fortran 90. It is meant to introduce basic Fortran
tools such as program structure, control flow, as well as some aspects
of numerical accuracy, precision and speed. These worksheets have nothing
to do with physics and can be used in any scientific programming course.
Further below are physics-related worksheets.*

**Worksheet 2:** (PDF, HTML):
Solution {Fortran 90 codes [real, complex]
, Compilation and Execution}

**Worksheet 3:** (PDF, HTML):
Solution {Fortran 90 codes [calculation module,
main
program, high-precision module
by Allan Miller], Compilation and Execution}

**Worksheet 4:** (PDF, HTML):
Solution {Fortran 90 code, `xmgrace`
plot, Compilation and Execution}

**Worksheet 5:** (PDF, HTML):
Solution {Fortran 90 code [calculation module,
main
program], Compilation and Execution}

**Worksheet 6:** (PDF, HTML):
Solution (Fortran 90 code [using `SimpleGraphics`
(HTML documentation, source
code, initialization script), using
FunGraphics (HTML documentation, source
code)], DISLIN plot, Compilation
and Execution)

**Electromagnetism in Fortran and ***Mathematica*

*This next series of worksheets do some meaningful and interesting
physics using Fortran 90 and Mathematica. They may be too complicated to
move to immediately after finishing the previous series
of worksheets. For yet more advanced interesting worksheets with more
emphasis on numerical analysis, please look at the Spring
2000 PHY480 webpage of problems and solutions.*

**Worksheet 7:** (PDF, HTML):
Solution {Fortran 90 code [source code, graphs
(as surface plot, as
contour plot, as vector field plot)
, Compilation and Execution], Mathematica
solution (HTML, notebook)}

**Worksheet 8:** (PDF, HTML):
Solution {Fortran 90 code [using Allan Miller's
quadrature code (utility module &
initialization
script, source of quadrature routines
& dependency module),
example
of trapezoid integration,
vector plot of field,
Compilation and Execution], Mathematica
solution (HTML,
notebook)}

**Worksheet 9:** (PDF, HTML):
Solution {Fortran 90 code [using RKSUITE (ODE
utility module, & initialization script,
source
of quadrature routines & example of RK4 Fortran
90 code), example of harmonic oscillator ODE using
RKSUITE & using Euler integration
(the plot), plots (case
1, case 2, case
3, case 4), Compilation
and Execution], Mathematica solution (HTML,
notebook)}

**Example for Final Exam**

*Use numerical integration to calculate the value of the error function
for a given real argument x. Write the result to a file and follow the
good-programming guidelines you've been given in class. Write your Fortran
90 code by hand, and pay attention to program organization and efficiency
as much as you can!*

Here is a sample solution that uses the module
from worksheet 2 for validation.