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

Fortran program for oscillator using Euler method

  1. Oct 22, 2013 #1
    I am trying to run a program with fortran. The program is about solving the Oscillator using Euler Method. I am trying to run this code and applying array arguments (as I want to extend it to 3 dimensions afterwards).
    When I try to compile, it comes up with an error "Unclassifiable statement at (1)". I don't know how to resolved this error.
    This is my code:

    program Oscilator
    implicit none

    real :: h !(Step size)
    integer, parameter :: n=100
    real, dimension(1:n) :: x,v,t
    external dx,dv
    integer :: i

    x(1) = 0.017
    t(1) = 0.0
    v(1) = 0.0

    write(*,*) 't x v'

    do while(t(i) <= n)
    h = t(i+1) - t(i)
    call Euler(h,x,v)
    write(6,'(4(e12.5,3x))') t(i), x(i), v(i)


    end do

    end program Oscilator

    function dx(t)
    implicit none
    real dx, t
    dx = exp(-0.9*t)*(-2.5*exp(0.557*t)-2.8*exp(-0.557*t))
    end function dx

    function dv(t)
    implicit none
    real dv, t
    end function dv

    subroutine Euler(h,x,v)
    implicit none
    real :: v,x,h,dv
    integer :: i

    x(i+1) = x(i) + v(i)*h
    v(i+1) = v(i) + dv(i)*h

    end subroutine Euler
  2. jcsd
  3. Oct 22, 2013 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    Please use
    Code (Text):
     tags when attaching source files.

    IDK about your error, but the program has some serious errors in implementation.

    For example, in the main program, you have a DO WHILE construct calculating values for the arrays t,x, and v.
    The problem is, the array index i is never defined or calculated, either inside or outside the DO WHILE construct.

    The condition for termination (t(i) <= n) can't be met because what value of the t array should be used?  There are no statements which define any of the values of the t array except for t(1) = 0.0.
  4. Oct 22, 2013 #3


    User Avatar

    Staff: Mentor

    I don't know either about this error. What compiler are you using?

    To add to what SteamKing said, here are some more flagrant errors:

    t(i) has never been defined. And usually, you would do this the other way around: you define h, and then increment t.

    If you're only going to print out t, x, and v, there is no need to store them in an array.

    This function is never used.

    This is an extremely strange equation to see in combination with the Euler method. You seem to already know what ##v(t)## is. What problem are you actually trying to solve?

    x and v are not arrays in the subroutine, so they shouldn't have any index. dv is not declared as external. dv takes a real as an argument, not an integer. i is never defined.
  5. Oct 22, 2013 #4


    User Avatar
    Science Advisor
    Homework Helper

    Most likely, the error is because you and your compiler have different ideas about whether the program file is in fixed format or free format. Or, you are using an editor which has added some unwanted (and invisible) characters to the file.

    But as others have said, there are plenty more problems to fix after have sorted that out!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Fortran program oscillator Date
How to buy Fortran Programming Software Commersial License Jan 30, 2018
Fortran 90/95 function Dec 17, 2015
Input/Output error with error code -5 Dec 16, 2015
Large/Infinite results Jun 18, 2015