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

Fortran complex numbers and do loops

  1. Nov 25, 2008 #1
    I have a very simple question, but have been unable to find an answer for it. When using fortran 90 can you use a DO loop to calculate a complex number? For example:

    Code (Text):

    COMPLEX FUNCTION forwards (tincdum,tstartdum,tenddum,fdum,ydum,idum,wdum&

      REAL, INTENT(IN):: tincdum,tstartdum,tenddum,wdum,lamdadum,ydum,idum
      COMPLEX, INTENT(IN):: ydum,idum
      COMPLEX:: fn

      DO ydum = tstartdum,tenddum,tincdum
       fn = fofy(idum,wdum,lamdadum,ydum,fn)
       ydum = ydum + tincdum*fn
      END DO

      forwards = ydum
     END FUNCTION forwards

    Thank you
  2. jcsd
  3. Dec 6, 2008 #2
    You can use a do loop to calculate a complex number. I am not sure if you can use a complex number for a do loop.

    Code (Text):
    DO ydum = tstartdum,tenddum,tincdum
    fn = fofy(idum,wdum,lamdadum,ydum,fn)
    ydum = ydum + tincdum*fn
    END DO
    In the above example, I doubt if ydum can be used as a do loop parameter, nor would it be desirable (under traditional fortran rules) to modify the parameter inside the loop.
    On the other hand, it is perfectly legitimate to do what you want to do using a while-loop.

    As a side note, ydum appears in both REAL and COMPLEX declarations. I am not sure if this was intended.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Fortran complex numbers and do loops
  1. Fortran Help (Do Loop) (Replies: 3)