Advertisement
Guest User

math project riemann sums

a guest
Nov 26th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # Name of the file is Riemann.py
  3. # Created by Joshua Kim on November 26, 2014
  4. import sys
  5.  
  6. # this handy bit of code will see if there is an argument given to the program;
  7. # if there is none, python won't crash and the program will move right along.
  8.  
  9. try:
  10.     y = sys.argv[1]
  11.     x = sys.argv[2]
  12. except:
  13.     print("No arguments given, moving right along to prompt statements")
  14.     y = input("y-value in inches? ")
  15.     x = input("x-value in inches? ")
  16.  
  17. # turn x and y variables from strings to numbers. is(annoying) == True
  18.  
  19. x = float(x)
  20. y = float(y)
  21.  
  22. # convert x from inches to centimeters
  23. x *= 2.54
  24. y *= 2.54
  25.  
  26. print(x,y)
  27.  
  28. area = 0.25 * 0.25
  29. print(area)
  30.  
  31. # since it's a midpoint sum, we have to find the midpoint of the x and y values
  32. # to plug in to the function.
  33.  
  34. point_x = (x/2.54 - 0.125)*2.54
  35. point_y = (y/2.54 - 0.125)*2.54
  36.  
  37. print(point_x)
  38. print(point_y)
  39.  
  40. # note that the ^ operator in the programming world shifts bytes, so ** is
  41. # used instead.
  42. z = 14.5161 * (1 - (point_x**2) / 116.532025 - (point_y**2) / 32.661225)
  43.  
  44. print(z)
  45.  
  46. volume = area * z
  47.  
  48. print("The volume in centimeters cubed is: " + str(volume))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement