-1

My program is meant to calculate the speed at which I hit the ground if I jump off a cliff.

I solved a differential equation. (Air resistance force is proportional to square of velocity.)

dv/dt = g (1 - v^2 / V_terminal^2)

positive v is downwards

now use the trick dv/dt = dv/dz dz/dt = dv/dz * v (z = height)

and integrate

integral v / (1-v^2/V_terminal^2) dv = integral g dz

gives you

(V_terminal^2 / 2) * ln(1-V_final^2/V_terminal^2) = gH

so

V_final = V_terminal*(1-e^(-2gh/V_terminal^2))^(1/2)

Now I put it in a program but whatever height I put in, it just comes out as the terminal velocity.

What am I doing wrong?

      PROGRAM JUMP
      IMPLICIT NONE
      REAL GETV
      REAL V
      REAL H
      REAL HGAPING
C https://en.wikipedia.org/wiki/Gaping_Gill    
      PARAMETER (HGAPING=98.)
      WRITE(6,*) 'EXAMPLE YOU JUMP ',HGAPING,' METRES'
      WRITE(6,*) 'YOU HIT GROUND AT ',GETV(HGAPING),' MPH'
 10   WRITE(6,*) 'HOW HIGH DO I JUMP FROM (METRES)?'
      READ(5,*) H
      WRITE(6,*) 'YOU JUMP FROM ',H,' METRES'
      WRITE (6,*) 'YOU HIT GROUND AT ',GETV(H),' MPH'
      GOTO 10
      END
      FUNCTION GETV(H)
      REAL GETV
      REAL H
      REAL G
C https://en.wikipedia.org/wiki/Standard_gravity      
      PARAMETER (G=9.81)
      REAL VTERMIN
C https://en.wikipedia.org/wiki/Free_fall
      PARAMETER (VTERMIN=53.)
      REAL METPS2MPH
      PARAMETER (METPS2MPH=2.2369363)
      GETV=VTERMIN*SQRT(1.-EXP(-2*G*H/(VTERMIN*VERMIN)))
     1     *METPS2MPH
      END

NOTE here is what you expect if it is working correctly. If you put in a big number then you should get approximately the terminal velocity, but if you put in a small number then you should get approximately SQRT(2*G*H). Both of these converted to mph by the scale factor included in the program.

Here is working version of the program neglecting air resistance

   (1/2) m V_final^2 = m g H  (simple energy equation)
      PROGRAM JUMP
      IMPLICIT NONE
      REAL GETV
      REAL V
      REAL H
      REAL HGAPING
C https://en.wikipedia.org/wiki/Gaping_Gill    
      PARAMETER (HGAPING=98.)
      WRITE(6,*) '*** THIS PROGRAM NEGLECTS AIR RESISTANCE ***'
      WRITE(6,*) 'EXAMPLE YOU JUMP ',HGAPING,' METRES'
      WRITE(6,*) 'YOU HIT GROUND AT ',GETV(HGAPING),' MPH'
 10   WRITE(6,*) 'HOW HIGH DO I JUMP (METRES)?'
      READ(5,*) H
      WRITE(6,*) 'YOU JUMP',H
      WRITE (6,*) 'YOU HIT GROUND AT ',GETV(H),' MPH'
      GOTO 10
      END
      FUNCTION GETV(H)
      REAL GETV
      REAL H
      REAL G
C https://en.wikipedia.org/wiki/Standard_gravity      
      PARAMETER (G=9.81)
      REAL METPS2MPH
      PARAMETER (METPS2MPH=2.2369363)
      GETV=SQRT(2*G*H)
     1     *METPS2MPH
      END

But the calculation including air resistance is going wrong somewhere.

Ian Bush
  • 6,996
  • 1
  • 21
  • 27
Adam
  • 1
  • 1

1 Answers1

1

This is an extended comment rather than an answer but those little boxes are too confining ... the code for falling through resistant air includes the calculation

GETV=VTERMIN*SQRT(1.-EXP(-2*G*H/(VTERMIN*VERMIN)))*METPS2MPH

and you need to check those variable names very carefully. The mistake you made is that you included implicit none in the program scope, but not in the function scope which is external to the program.

Now, onto something which is definitely a comment: why oh why are you writing Fortran like it was 1985 ? If you are paying for an education which includes teaching you how to program in Fortran ask for most of your money back for that course, maybe consider switching institutions. And if you are teaching yourself throw away your granddad's textbook and buy yourself one written in the last decade or so.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
  • It is a bit late for me to switch institutions, given that it is some decades since I graduated. Fortunately, I did not have to pay for my education at that time, so even though Cambridge University showed their inadequacy by teaching only the version of Fortran that was available at the time (which is of course still supported) rather than predicting future developments, at least I didn't have to pay for it. What you have not done is make a compelling case for having to relearn it all. PS both my granddads died in the 1960s. – Adam Jun 13 '20 at 12:06
  • Anyhow the answer seems to be that with the variable name corrected (VERMIN! Oh dear, thank you)... the air resistance makes less difference than might have been imagined. In the Gaping Gill example it is 83.5 mph instead of 98.1 mph. Okay that's 28% less kinetic energy but probably still more fatal than COVID unless you're really really old and still writing COBOL. Bet it still compiles though... – Adam Jun 13 '20 at 12:39
  • Unfortunately I can't dupe-hammer this one closed, I already VTCed because the error is the result of a typo. If I could, I would close it as a duplicate of https://stackoverflow.com/questions/24337413/where-to-put-implicit-none-in-fortran. i don't really think its continued presence on SO adds anything at all. – High Performance Mark Jun 14 '20 at 09:57