Fortran complex numbers and do loops

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 9K views
freja
Messages
7
Reaction score
0
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:
COMPLEX FUNCTION forwards (tincdum,tstartdum,tenddum,fdum,ydum,idum,wdum&
                                      &,lamdadum)
  IMPLICIT NONE

  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
[code/]

Thank you
 
Physics news on Phys.org
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:
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.
See
http://www.tat.physik.uni-tuebingen.de/~kley/lehre/ftn77/tutorial/loops.html

As a side note, ydum appears in both REAL and COMPLEX declarations. I am not sure if this was intended.