Computers in Engineering WWW Site - Example 6.5

# Example 6.5

#### FORTRAN Version

```!
PROGRAM P68
!
IMPLICIT NONE
INTEGER :: J
REAL :: X,Y
!
INTERFACE
FUNCTION GAUSS(X,U,SD)
IMPLICIT NONE
REAL, INTENT(IN) :: X,U,SD
REAL :: GAUSS
END FUNCTION GAUSS
END INTERFACE
!
PRINT *, 'This is Program >> P68  - GAUSS Function'
!
!     Example of using a function
!     on the RHS of an assignment statement
!
X = 0.0
L1:   DO J =1,11  ! 11 steps in the positive X direction
Y=5.0*GAUSS(X,0.0,1.0)+2.5
!
!     The Gaussian or Normal curve has
!     been scaled and translated
!
PRINT *,X,Y
X = X + 0.5     ! Increase X by a step of .5
END DO L1
STOP
END PROGRAM P68
!
!     Example of writing a function
!
FUNCTION GAUSS(X,U,SD)
IMPLICIT NONE
REAL, INTENT(IN) :: X,U,SD
REAL :: C,GAUSS
C=1.0/(SD*SQRT(2.0*3.14159))
GAUSS=C*EXP(-(X-U)**2/(2.0*SD**2))
RETURN
END FUNCTION GAUSS
```
OUTPUT:
```
+--------------------------------------------------+
|     32-bit Power for Lahey Computer Systems      |
|   Phar Lap's 386|DOS-Extender(tm) Version 7.0    |
|  Copyright (C) 1986-94 Phar Lap Software, Inc.   |
|           Available Memory = 14880 Kb            |
+--------------------------------------------------+

This is Program >> P68  - GAUSS Function
0.000000        4.49471
0.500000        4.26033
1.00000        3.70985
1.50000        3.14759
2.00000        2.76995
2.50000        2.58764
3.00000        2.52216
3.50000        2.50436
4.00000        2.50067
4.50000        2.50008
5.00000        2.50001
```

#### Pascal Version

```PROGRAM p68 (input, output);
VAR
y : REAL;

FUNCTION gauss ( x, u, sd : REAL ) : REAL;
VAR
c : REAL;
BEGIN
c := 1.0 / ( sd * sqrt ( 2.0 * 3.14159 ) );
gauss := c * exp ( -sqr ( x - u ) / ( 2.0 * sqr ( sd ) ) )
END;

BEGIN
y := 5.0 * gauss ( 2.5, 0.0, 1.0 ) + 9.5;
writeln ( y )
END.
```