-
Notifications
You must be signed in to change notification settings - Fork 0
/
KINESOLV-LOW.py
126 lines (109 loc) · 4.78 KB
/
KINESOLV-LOW.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Created by Rohan Reddy
# Updated by Spencer Boggs
#Version with the lowest RAM usage
import math
print("")
print(" Welcome to Kinematic")
print(" Equation Solver!")
print(" Created by Rohan Reddy")
print(" Updated by Spencer Boggs")
print("")
print(" Enter any unknown value as u")
print(" Ensure velocities are in m/s,")
print(" acceleration is in m/s^2, time")
print(" is in s, and distance is in m")
print("")
input(" Press [Enter] to Start")
while True:
print("")
Vfinal = input("Enter Vfinal (v): ")
Vinitial = input("Enter Vinitial (v0): ")
acceleration = input("Enter acceleration (a): ")
time = input("Enter time (t): ")
deltaX = input("Enter displacement (x-x0): ")
print("Enter variable to solve for. ")
solveFor = input("(v, v0, a, t, x): ")
#V = v0 + at
#Requires v0, a, t
if (solveFor == "v") and (Vinitial != "u") and (acceleration != "u") and (time != "u"):
Vfinal = float(Vinitial) + (float(acceleration) * float(time))
print("")
print("v = " + str(Vfinal) + "m/s")
print("Equation: v = v0 + at")
#Requires v, a, t
elif (solveFor == "v0") and (Vfinal != "u") and (acceleration != "u") and (time != "u"):
Vinitial = float(Vfinal) - (float(acceleration) * float(time))
print("")
print("v0 = " + str(Vinitial) + "m/s")
print("Equation: v = v0 + at")
#Requires v0, v, t
elif (solveFor == "a") and (Vfinal != "u") and (Vinitial != "u") and (time != "u"):
acceleration = (float(Vfinal) - float(Vinitial)) / float(time)
print("")
print("a = " + str(acceleration) + "m/s^2")
print("Equation: v = v0 + at")
#Requires v0, v, a
elif (solveFor == "t") and (Vfinal != "u") and (Vinitial != "u") and (acceleration != "u"):
time = (float(Vfinal) - float(Vinitial)) / float(acceleration)
print("")
print("t = " + str(time)+ "s")
print("Equation: v = v0 + at")
#V^2 = v0^2 + 2ax
#Requires v0, a, x
elif (solveFor == "v") and (Vinitial != "u") and (acceleration != "u") and (deltaX != "u"):
Vfinal = math.sqrt(abs(float(Vinitial)**2 + 2 * float(acceleration) * float(deltaX)))
print("")
print("v = " + str(Vfinal) + "m/s")
print("Equation: V^2 = v0^2 + 2ax")
#Requires v0, v, a
elif (solveFor == "x") and (Vinitial != "u") and (acceleration != "u") and (Vfinal != "u"):
deltaX = (float(Vfinal)**2 - float(Vinitial)**2) / (2 * float(acceleration))
print("")
print("x = " + str(deltaX)+ "m")
print("Equation: V^2 = v0^2 + 2ax")
#Requires v, a, x
elif (solveFor == "v0") and (deltaX != "u") and (acceleration != "u") and (Vfinal != "u"):
Vinitial = math.sqrt(abs(float(Vfinal)**2 - (2 * float(acceleration) * float(deltaX))))
print("")
print("v0 = " + str(Vinitial) + "m/s")
print("Equation: V^2 = v0^2 + 2ax")
#Requires v, v0, deltaX
elif (solveFor == "a") and (deltaX != "u") and (Vinitial != "u") and (Vfinal != "u"):
acceleration = (float(Vfinal)**2 - float(Vinitial)**2) / (2 * float(deltaX))
print("")
print("a = " + str(acceleration)+ "m/s^2")
print("Equation: V^2 = v0^2 + 2ax")
#x = v0t + 1/2 * at^2
#Requires v0, t, a
elif (solveFor == "x") and (Vinitial != "u") and (acceleration != "u") and (time != "u"):
deltaX = float(Vinitial) * float(time) + (0.5 * float(acceleration) * float(time)**2)
print("")
print("x = " + str(deltaX) + "m")
print("Equation: x = v0t + 1/2 * at^2")
#Requires x, v0, t
elif (solveFor == "a") and (Vinitial != "u") and (deltaX != "u") and (time != "u"):
acceleration = (float(deltaX) - float(Vinitial) * float(time)) / (0.5 * float(time)**2)
print("")
print("a = " + str(acceleration)+ "m/s^2")
print("Equation: x = v0t + 1/2 * at^2")
#Requires x, a, t
elif (solveFor == "v0") and (acceleration != "u") and (deltaX != "u") and (time != "u"):
Vinitial = (float(deltaX) - 0.5 * float(acceleration) * float(time)**2) / float(time)
print("")
print("v0 = " + str(Vinitial) + "m/s")
print("Equation: x = v0t + 1/2 * at^2")
#Requires a, v0, x
elif (solveFor == "t") and (acceleration != "u") and (deltaX != "u") and (Vinitial != "u"):
a = 0.5 * float(acceleration)
b = float(Vinitial)
c = float(deltaX) * -1
if ((-b + math.sqrt(abs(b**2 - 4 * a * c)))/(2*a)) < 0:
time = ((-b - math.sqrt(abs(b**2 - 4 * a * c)))/(2*a))
else:
time = (-b + math.sqrt(abs(b**2 - 4 * a * c)))/(2*a)
print("")
print("t = " + str(time)+ "s")
print("Equation: x = v0t + 1/2 * at^2")
else:
print("Unsolvable.")
print("Double check your inputs.")