Python - Calculate Lorentz Factor/Gamma Factor

by matt392 in Circuits > Software

112 Views, 1 Favorites, 0 Comments

Python - Calculate Lorentz Factor/Gamma Factor

Lorentz-Factor-Formula.png
print ("This program will calculate the Lorentz Factor/Gamma Factor.")

import math

#  Formula for calculating the Lorentz Factor:
#  Lorentz Factor = (1/(math.sqrt((1-((velocity**2)/(speed of light**2))))))

###########################################

#  1 function: solve for Lorentz Factor
# math.sqrt(x) - returns square root of "x"
# Function to solve for Lorentz Factor
# Solve for Lorentz Factor: enter velocity 
#  Lorentz Factor = (1/(math.sqrt((1-((velocity**2)/(speed of light**2))))))
def SolveForLorentzFactor():
    print ("Solving for the Lorentz Factor.")
#  Square root function: math.sqrt(x)
    Velocity = float(input("Enter the velocity as a decimal percentage of the speed of light (ie: .457): ") )
    SpeedOfLight = (2.998*(10**8) )
    VelocityFinal = Velocity * SpeedOfLight
    LorentzFactor = (1/(math.sqrt((1-((VelocityFinal**2)/(SpeedOfLight**2))))))
    print("The Lorentz Factor is: ", LorentzFactor)
#    Lorentz Factor = (1/(math.sqrt((1-((velocity**2)/(speed of light**2))))))

ContinueCalculations = "y"

# Check to see if the user wants to continue to calculate Lorentz Factor
while (ContinueCalculations=="y"):
    SolveForLorentzFactor()
    ContinueCalculations = input("Would like to do another calculation for the Lorentz Factor/Gamma Factor? (y/n): ")
    
print("==================================")
print ("Thank you to Greg's video on Youtube for calculation information.")
print ("http://physics.gpclements.com/")
print ("Thank you to www.FxSolver.com for information on this formula.")


Downloads