Introduction: Python - Using Relativistic Redshift to Calculate Velocity of Star/Galaxy/Quasar

About: Occupation: tech support

Python program that uses the relativistic redshift formula to calculate the velocity of a star, galaxy or quasar.

Code is attached and below.

Also available as a custom GPT called Velocity Star that was trained on the code:

https://chat.openai.com/g/g-6xpZIMe3k-velocity-star

========================

print ("Calculate the relativistc redshift of a star or galaxy.")

# Function to find redshift
def calculateRedshift():
# Observed wavelength entered by user and converted to an integer
observedWavelength = int(input("Enter the observed wavelength in Angstroms: "))

# Wavelength of element entered by user and converted to an integer
elementWavelength = int(input("Enter the element's wavelength in Angstroms: "))

# Calculate the change or shift in the wavelength
changeWavelength = observedWavelength - elementWavelength
print ("The redshift formula is: redshift = (change in wavelength/wavelength of the element)")
redshift = (changeWavelength/elementWavelength)
print ("The redhshift of the star or galaxy is:", redshift)
return redshift

redshiftCalculated = calculateRedshift()
print("------")
print("The relativistic redshift formula is: ( (((redshiftCalculated+1)^2) - 1)/(((redshiftCalculated+1)^2) + 1) ) * 300000)")
velocity = (( (((redshiftCalculated+1)**2) - 1)/ (((redshiftCalculated+1)**2) + 1) ) * 300000)
print ("The velocity is: ",velocity, "km/s")
print("------")
print ("Thank you to Professor Morgan at the University of Northern Iowa for the formula and explanation.")
print ("Note that a positive value means the object is moving away from Earth.")
print ("A negative value means that the object is moving towards Earth.")

Step 1: Python - Using Relativistic Redshift to Calculate Velocity of Star/Galaxy/Quasar

print ("Calculate the relativistc redshift of a star or galaxy.")

# Function to find redshift
def calculateRedshift():
# Observed wavelength entered by user and converted to an integer
observedWavelength = int(input("Enter the observed wavelength in Angstroms: "))

# Wavelength of element entered by user and converted to an integer
elementWavelength = int(input("Enter the element's wavelength in Angstroms: "))

# Calculate the change or shift in the wavelength
changeWavelength = observedWavelength - elementWavelength
print ("The redshift formula is: redshift = (change in wavelength/wavelength of the element)")
redshift = (changeWavelength/elementWavelength)
print ("The redhshift of the star or galaxy is:", redshift)
return redshift

redshiftCalculated = calculateRedshift()
print("------")
print("The relativistic redshift formula is: ( (((redshiftCalculated+1)^2) - 1)/(((redshiftCalculated+1)^2) + 1) ) * 300000)")
velocity = (( (((redshiftCalculated+1)**2) - 1)/ (((redshiftCalculated+1)**2) + 1) ) * 300000)
print ("The velocity is: ",velocity, "km/s")
print("------")
print ("Thank you to Professor Morgan at the University of Northern Iowa for the formula and explanation.")
print ("Note that a positive value means the object is moving away from Earth.")
print ("A negative value means that the object is moving towards Earth.")