Introduction: Python - Using Relativistic Redshift to Calculate Velocity of Star/Galaxy/Quasar
Python program that uses the relativistic redshift forumla to calculate the velocity of a star, galaxy or quasar.
Code is attached and below.
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.")