ClassicConnect ClassicConnect
"640k ought to be enough for everybody."
 
FAQ :: Search :: Memberlist :: Usergroups :: Register
Profile :: Log in to check your private messages :: Log in

fortran physics calculations

 
Post new topic   Reply to topic    ClassicConnect Forum Index -> Software and Web Design
View previous topic :: View next topic  
Author Message
ravenbrook
Member


Joined: 03 May 2026
Age: 18
Posts: 12
Location: Scotland

PostPosted: Mon May 04, 2026 3:21 pm    Post subject: fortran physics calculations Reply with quote

i am a beginner at programming, but i am working on making a basic library of physics equations in fortran. i made one for length contraction, working both ways. i need to add an option to find velocity. just thought some of you might be interested.

Code:

program calc
   use, intrinsic :: iso_fortran_env, only : real_kinds, &
 & real32, real64, real128
   implicit none
   character*1 :: type
   real(kind=real128) :: c, v, l, length
   c = 299792458d+0

   print *, "Are you working out contracted length (i) or original length (p)?"
   read *, type
   if( type == 'i' ) then
   print *, "Please enter your velocity: "
   read *, v
   print *, "Please enter the length of the object: "
   read *, l
   length = l * sqrt( 1 - (v / c)**2 )
   print *, 'The contracted length is ', length

   else if( type == 'p' ) then
   print *, "Please enter your velocity: "
   read *, v
   print *, "Please enter the length of the object: "
   read *, length
   l = length / sqrt( 1 - (v / c)**2 )
   print *, 'The original length is  ', l

   else
   print *, "That wasn't an option I gave you was it?"

end if

end program calc


should note that this was compiled as fortran 90
_________________
The front fell o- wait what? It didn't fall off? Oh.
Back to top
View user's profile Send private message Visit poster's website
ravenbrook
Member


Joined: 03 May 2026
Age: 18
Posts: 12
Location: Scotland

PostPosted: Wed May 06, 2026 3:09 pm    Post subject: Reply with quote

i have improved it by adding an option to calculate starting velocity and just general sanity improvements.
Code:
program calc
   use, intrinsic :: iso_fortran_env, only : real_kinds, &
 & real32, real64, real128
   implicit none
   character*1 :: type
   real(kind=real128) :: c, v, l, length
   c = 299792458d+0

   print *, "Are you working out: "
   print *, "(1) Contracted length"
   print *, "(2) Original length"
   print *, "(3) Velocity"
   read *, type

   if( type == '1' ) then

   print *, "Please enter your velocity: "
   read *, v
   print *, "Please enter the length of the object: "
   read *, l

   l = abs(l)

   length = l * sqrt( 1 - (v / c)**2 )
   print *, 'The contracted length is ', length

   else if( type == '2' ) then

   print *, "Please enter your velocity: "
   read *, v
   print *, "Please enter the length of the object: "
   read *, length

   length = abs(length)

   l = length / sqrt( 1 - (v / c)**2 )
   print *, 'The original length is  ', l

   else if ( type == '3' ) then
   print *, "What is the original length?"
   read *, l
   print *, "What is the contracted length?"
   read *, length

   v = c * sqrt( 1 - ( length / l ) ** 2 )
   print *, "The velocity is: ", v

   else

   print *, "That wasn't an option I gave you was it?"

end if

end program calc


(edited the code as i had made some changes)
_________________
The front fell o- wait what? It didn't fall off? Oh.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    ClassicConnect Forum Index -> Software and Web Design All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



smartDark Style by Smartor
Powered by phpBB 2.0.25 CC Mod © 2001, 2002 phpBB Group
 
Page generation time: 0.0135s (PHP: 93% - SQL: 7%) - SQL queries: 11 - GZIP enabled - Debug on