How to Use FORTRAN Do Loops for Solving Equations - Step by Step Guide"

  • Context: Fortran 
  • Thread starter Thread starter McAfee
  • Start date Start date
  • Tags Tags
    Fortran Loop
Click For Summary

Discussion Overview

The discussion revolves around using FORTRAN do loops to solve equations, specifically focusing on how to implement a loop that updates a variable based on previous calculations. The scope includes programming techniques and coding practices in FORTRAN.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant describes their FORTRAN code and seeks assistance on how to loop a computed value back into an equation for further calculations.
  • Another participant suggests moving the calculation of a variable outside the loop and updating it within the loop after writing the output.
  • A different participant inquires about the use of call statements within a do loop, providing an example of their own code.
  • A response advises the inquiring participant to start a new thread for their unrelated question.

Areas of Agreement / Disagreement

Participants generally agree on the need for clarity in coding practices, but there is no consensus on the unrelated question about call statements in do loops, as it was redirected to a new thread.

Contextual Notes

The discussion does not resolve potential issues related to the structure of the FORTRAN code or the implications of moving statements in relation to the loop.

McAfee
Messages
96
Reaction score
1
Hey guys,

I'm new to fortran and I'm having a slight problem. I put my code below as reference. I first set up a my known values. Then I used an equation to solve for v. After I solve for v I then computed c which involves v.

What I'm now trying to do is to loop the value I got for c back into the equation [c=((r*t)/(p+(a/(v**2))))+b]. So the c would become v and compute a new number.

Any ideas on how I could accomplish that? Thanks for help in advance.

Code:
 program homework
      open (2, file='output.txt')
      a=366*10**3
      b=0.0429
      p=100
      t=300
      r=8.3145



      DO 1, i=0,5

      v=(r*t)/p
      c=((r*t)/(p+(a/(v**2))))+b



      write(2,*) c
      
      
      
      
   1  continue
      
      
      
      
      end program
 
Technology news on Phys.org
First: move the statement "v=(r*t)/p" out of the loop (just before the "do" statement.
Then, after the write statement, add this statement: v=c

That's all it takes.
 
Hi everyone;
I want to know whether a call statement is used in a do loop. For example;

do 100 ii = 1, 10

call subroutine getsum(ii,20,XX,JJ)

100 continue

Here XX and JJ are parameters.
 
selmayda,
Please start a new thread with your question. Tacking an unrelated question onto an existing thread is known as "hijacking."
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 26 ·
Replies
26
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 22 ·
Replies
22
Views
5K