Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB Write a script lumin that will calculate and print the luminosity L of a

ID: 3789289 • Letter: M

Question

MATLAB

Write a script lumin that will calculate and print the luminosity L of a star in Watts. The luminosity L is given by L = 4 pi d^2 b where d is the distance from the sun in meters and b is the brightness in Watts/meters^2. Here is an example of executing the script: >> lumin This script will calculate the luminosity of a star. When prompted, enter the star's distance from the sun in meters, and its brightness in W/meters squared. Enter the distance: 1.26e12 Enter the brightness: 2e-17 The luminosity of this star is 399007399.75 watts

Explanation / Answer

import math

def main() :
   print "This script will calculate the luminosity of a star."
   print "When prompted, enter the star's distance from the sun"
   print "in meters, and its brightness in W/meters squared."
   d = float(raw_input("Enter the distance: "))
   b = float(raw_input("Enter the brightness: "))

   print "The luminosity of this star is "+str(4*math.pi*d*d*b)+" watts"


if __name__ == "__main__":main()

Sample Output:

This script will calculate the luminosity of a star.
When prompted, enter the star's distance from the sun
in meters, and its brightness in W/meters squared.
Enter the distance: 3.4e12
Enter the brightness: 2.3e-18
The luminosity of this star is 334114661.895 watts