1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Fortran Program - Calculate the Function

  1. Apr 3, 2014 #1
    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


  2. jcsd
  3. Apr 3, 2014 #2


    User Avatar

    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.
  4. Apr 3, 2014 #3
    the program works

    but the answers all zero
  5. Apr 3, 2014 #4


    User Avatar

    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted