Fortran Fortran complex numbers and do loops

AI Thread Summary
In Fortran 90, a DO loop can be used to calculate a complex number, but using a complex number as a loop variable is not advisable. The example provided demonstrates a DO loop iterating over a real variable, while the complex variable `ydum` is modified within the loop, which is not recommended according to traditional Fortran practices. Instead, using a WHILE loop could be a better approach for such calculations. Additionally, there is a concern regarding the dual declaration of `ydum` as both REAL and COMPLEX, which may lead to confusion or errors in the code.
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
 
Technology 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.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
4
Views
2K
Replies
8
Views
4K
Replies
13
Views
3K
Replies
4
Views
2K
Replies
8
Views
2K
Back
Top