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
AI Thread 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."
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
8
Views
4K
Replies
12
Views
1K
Replies
8
Views
2K
Replies
12
Views
2K
Replies
59
Views
11K
Replies
8
Views
4K
Replies
22
Views
5K
Back
Top