Fortran has been so successful at helping engineers to approximate equations
that for many it has become a key part of the engineering process. But with
many of the engineers who coded in Fortran now retiring, it leaves a lot of
legacy bits unsupported out there. All the more a problem since Fortran and
Microsoft products don't naturally go together.
"Many of these legacy programs are rapidly turning into black boxes and that's
a worry for many engineering departments," says John Sheehan, VP of services
at Mathsoft, makers of Mathcad, a software tool for math calculations.
It was actually at the request of several customers who were worried about
the growing black-box nature of their Fortran programs that Sheehan looked into
how Mathcad—an interpretive math engine with natural math notation—could
help. Mathcad is also a strong collaborative work tool—which makes it
easy for engineers to publish and share information.
Although engineers can enter an exact system of equations into Mathcad, Sheehan
discovered that some engineers want to replicate exactly the results they were
getting in Fortran—possibly they need the margin of error for backward
compatibility. He then demonstrated a better approach—taking the original
partial differential equations (which the Fortran code was trying to approximate)
and typing them directly in Mathcad.
| You need this trick if: You are
currently using legacy Fortran programs for approximating linear and nonlinear
algebraic or differential equations and need these equations in a format
where they can not only be recalculated but also shared and understood by
others. |
Fortran to Mathcad: A Conversion Plan
This is the system of equations that John set
up to solve...
ut(x,t) - uxx(x,t) = 0
u(x,0)
= f(x)
u(0,t)
= p(t) u(1,t) =
q(t)
u:= Pdesolve [ u,x (0 1), t, (0 0.5)]
solve for u (x,t) over the range
x
= 0 to 1 and t = 0 to 0.5
x:=0,0.01 .. 1 t:= 0.5
...then he compared the results he generated using
Mathcad (by using the column operator) to results from the FORTRAN program...
| |
Mathcad Results |
|
|
| |
T=0.50 |
Numerical |
Exact |
| |
0.000 |
0.000 |
0.000 |
| |
0.100 |
0.260 |
0.222 |
| |
0.200 |
0.494 |
0.423 |
| |
0.300 |
0.680 |
0.582 |
|
M=
|
0.400 |
0.800 |
0.684 |
| |
0.500 |
0.841 |
0.719 |
| |
0.600 |
0.800 |
0.684 |
| |
0.700 |
0.680 |
0.582 |
| |
0.800 |
0.494 |
0.423 |
| |
0.900 |
0.260 |
0.222 |
| |
1.000 |
0.000 |
0.000 |
|
|
Fortran Results
|
|
|
| T=0.50 |
Numerical |
Exact |
| X=0.0 |
0.000000 |
0.000000 |
| X=0.1 |
0.259879 |
0.222242 |
| X=0.2 |
0.494319 |
0.422730 |
| X=0.3 |
0.680372 |
0.581837 |
| X=0.4 |
0.799826 |
0.683991 |
| X=0.5 |
0.840987 |
0.719190 |
| X=0.6 |
0.799826 |
0.683991 |
| X=0.7 |
0.680372 |
0.581837 |
| X=0.8 |
0.494319 |
0.422729 |
| X=0.9 |
0.259879 |
0.222242 |
| X=1.0 |
0.000000 |
0.000000 |
|
| ...and then showed that you can obtain the exact
solution using Mathcad's built-in Pdesolve function. |
 |
For John's complete instructions for converting a Fortran program with several
do laps into an equivalent Mathcad program using Mathcad's while loop, go to:
http://rbi.ims.ca/4392-553.
Got a cool software trick? Send us details, including any documentation
and supporting code, to kfield@reedbusiness.com.
If we publish your trick, we'll send you a super cool, limited-edition Design
News t-shirt.