Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Please help me: a problem on my FOTRAN program

  1. Apr 18, 2012 #1
    I have written a program in FOTRAN for solving a equation [f(t0,y0)= 1/2*(t-y) by EulerMethod

    I'm in the learning stage of FOTRAN.
    after executing my program and save the result in txt file
    the result For example be
    1.000000000000000 1.000000000000000
    2.000000000000000 1.000000000000000
    3.000000000000000 1.000000000000000
    4.000000000000000 1.000000000000000
    5.000000000000000 1.000000000000000
    6.000000000000000 1.000000000000000
    7.000000000000000 1.000000000000000
    8.000000000000000 1.000000000000000
    9.000000000000000 1.000000000000000
    I don't know what the problem in this function; because the other function working perfectly
    as f(t0,y0)= (t+y)

    So please don't mind if my program has got any silly mistakes.

    My code

    program EulerMethod
    implicit none

    print*,"Enter the interval a,b ,the value of the step-size h and the value of y_0"

    open(1, file="resultEuler.txt",status='new',position="rewind")

    call euler(y_0,a,b,h)

    subroutine euler(y_0,a,b,h)
    implicit none
    real(8), intent(inout)::a,h,b,y_0
    real(8):: y,t
    do while(t<=b)
    write(1,*)t, y
    end do
    end subroutine
    function f(y,t)
    implicit none


    end function

    end program EulerMethod
  2. jcsd
  3. Apr 18, 2012 #2
    Please provide the input a,b,h,y_0 for a simple example and what the output should be.

    Just saying "it prints 1,2,3,4,5,6,7,8. what is wrong with it?" doesn't give enough information for someone to be able to step through the problem and find the error.
  4. Apr 18, 2012 #3


    Staff: Mentor

    I suspect that your f function is causing problems.
    Code (Text):

    function f(y,t)
     implicit none
    end function
    In the value you return, you should replace 1/2 by 0.5. I'm pretty sure that 1/2 is causing your function to always return 0. This is because 1/2 evaluates to 0. In other words, integer division is being performed, not floating point division.

    BTW, the name of the language is FORTRAN.
  5. Apr 18, 2012 #4
    ^_______^ Thanks guys
    thank you Mark44 for found the problem ,,, my program running perfectly .....

    BTW, I know the name of this language is ForTran ,,,, but i had syntax error hhhhhhhh
    .... Thank you again
    Bye :)
  6. Apr 18, 2012 #5


    Staff: Mentor

    Good to hear.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook