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

  • Thread starter Thread starter McAfee
  • Start date Start date
  • Tags Tags
    Fortran Loop
Click For Summary
The discussion revolves around a Fortran programming issue where the user is trying to loop a computed value, c, back into an equation to recalculate v. The user initially sets known values and computes v using the equation v=(r*t)/p, then calculates c using c=((r*t)/(p+(a/(v**2))))+b. To achieve the desired looping, a suggestion is made to move the calculation of v outside the loop and assign c to v after writing c to the output. Additionally, a separate question about using a call statement within a do loop is raised, but the community advises starting a new thread for unrelated inquiries to avoid hijacking the current discussion.
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."
 
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 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
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
11K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 22 ·
Replies
22
Views
5K