from sympy.physics.units import newton, m
from sympy import *
from sympy import N as Num
from mpmath import degrees, radians
print("------ User input ----------------------")
symbolic = True
symbolic = False
if symbolic:
M = var("M")
G = var("G")
l = var("l")
r1, r2 = var("r1, r2")
else:
M = 10 *newton*m
G = 79*10**9 *newton/m/m
l = 1 *m
r1 = S(5)/1000 *m
r2 = S(10)/1000 *m
print("------ Radius --------------------------")
x = var("x")
rx = r2 - (r2-r1)*x/l
Ip = pi/2*rx**4
print("------ Integration ---------------------")
i = 1/Ip.simplify()
I = integrate(i, (x, 0, l))
pprint(["I", I.simplify()])
term = -l/(r2-r1)
anti = -2/pi/3*rx**(-3)*term
i_check = diff(anti, x).simplify()
print("Should be \"True\":", i == i_check)
theta_l = M/G*I.simplify()
pprint(["theta(l)", theta_l])
pprint(["theta(l) / deg", Num(degrees(theta_l),2)])
------ User input ----------------------
------ Radius --------------------------
------ Integration ---------------------
2800000000
[I, ----------]
3
3*pi*m
('Should be "True":', True)
28
[theta(l), ------]
237*pi
[theta(l) / deg, 2.2]