# Fortran Program - Calculate the Function

1. Apr 3, 2014

### Haleemos

1. The problem statement, all variables and given/known data

F(x) = exp(-a x^2) cos bx
for -100 =< x >= 100 , a=13 and b=7.

2. Relevant equations
...

3. The attempt at a solution

program main

implicit double precision (A-H,O-Z)
implicit integer (I-N)

DO I = -100,100
X = I * 1D0

F = DEXP(-A * X**2) * DCOS(B * X)

A = 13
B = 7

PRINT*,F
ENDDO

STOP
END

2. Apr 3, 2014

### Staff: Mentor

Have you tested the program to see if it works?

Because it will not give the right result. Check the order in which you are doing things.

3. Apr 3, 2014

### Haleemos

the program works

4. Apr 3, 2014

### Staff: Mentor

Are you sure about that? Because it is not the case when I run it.

You only made one mistake, which is that a and b are set too late. And they shouldn't be inside the loop: set them at the begining of the program. Might as well also set them directly as double precision
Code (Text):
a = 13.d0
b = 7.d0
Also, instead of multiplying by 1D0, set I to double precision using
Code (Text):
X = dble(I)
This is more efficient as there will not be an unnecessary multiplication every time.

I also suggest that you print out both x and F, which makes it easier to check the output and plot the results.