Arithmetic in Fortran: Higher operators

You may be aware that "Fortran" is a contraction of "formula translator." It should then be no surprise that Fortran includes a full complement of mathematical operations in addition to the basic arithmetic operations of addition, subtraction, multiplication and division.

In the previous lesson we saw one such operation, exponentiation, which is symbolized by the double asterisk **:

      A = B ** 3

Here the variable A is given a value that is equal to the cube of another variable, B.

Fractional powers may be used: for example, if we want to take the fourth root of some variable C, we could write:

      D = C ** 0.25

The following operators take the form of functions. A function operates on one or more inputs, called arguments, that are placed in parentheses after the function. Some of the most commonly used mathematical functions are as follows:

Function Meaning
Y = ABS (X)
Absolute value; Y is the absolute value of X.
Y = SQRT (X)
Square root; Y is the square root of X. Attempting to take the square root of a negative number will produce an error.
Y = EXP (X)
Exponential of the argument X; that is, the variable e to the power X.
Y = ALOG (X)
Natural logarithm of the argument X. Attempting to take the logarithm of a negative number will cause the system to report an error.
Y = SIN (X)
Sine of the argument X. Important: X is expressed in radians.
Y = COS (X)
Cosine of the argument X. Important: X is expressed in radians.
Y = TAN (X)
Tangent of the argument X. Important: X is expressed in radians.
Y = ASIN (X)
Arcsine of the argument X. The result will be in radians.
Y = ACOS (X)
Arccosine of the argument X. The result will be in radians.
Y = ATAN (X)
Single-argument arctangent. Here Y is the arctangent of the argument X. The result will be in radians, with a value between -pi/2 and +pi/2.
Y = ATAN2 (Y, X)
Two-argument arctangent; the result is the arctangent of Y/X, in radians. The use of two arguments allows the determination of the quadrant of the angle, so that the result is between -pi and +pi rather than -pi/2 and +pi/2.

Assignment: Write a brief program to compute the value of the Coriolis parameter every 10 degrees of latitude from the South Pole to the North Pole. Remember that Fortran trigonometric functions work in radians!

 

Next: Repetitive instructions

Back to the main page for the programming tutorial.