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."
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

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