from sympy.physics.units import *
from sympy import *
from sympy import N as Num
import matplotlib.pyplot as plt
from numpy import linspace, full_like, array, arange
print("------ User input ----------------------------")
symbolic = True
symbolic = False
if symbolic:
F = var("F")
(l, b, hl) = var("l, b, hl")
hx = var("h_x")
else:
F = 1 * newton
(l,b,hl) = (600 *mm, 6 *mm, 30 *mm)
hx = 10 *mm
print("\n--- c: Section modulus ---------------------")
def Wy(b,h):
return b/6 * h**2
Wl = Wy(b, hl)
pprint(["W_y at x=l", Wl])
print("\n--- d: Stress ------------------------------")
x = var("x")
Mx = -x*F
Mx_max = Abs(Mx.subs(x,l))
pprint(["|M(x=l)|", Mx_max])
sig_max = Mx_max / Wl
pprint(["sig_max", sig_max])
print("\n--- e: --------------------------------------")
Wx = Wy(b,hx)
eq = Eq( F*l/Wl, F*x/Wx )
x_star = solve(eq,[x])[0]
pprint(["x^*", x_star])
print("\n--- f: Plot ---------------------------------")
xia = linspace(float(0), float(1))
xi = var("xi")
f = xi**0.5
f = lambdify(xi,f,"numpy")
f = array(f(xia))
tmp = plt.plot(xia, f, label="$h_{\\xi} = \sqrt{\\xi}$")
tmp = plt.xlabel("$\\xi = x / l$")
tmp = plt.legend(loc="best")
plt.savefig("2.4.3_B_sqrt.png", transparent=True)
plt.show()
------ User input ----------------------------
--- c: Section modulus ---------------------
3
9*m
[W_y at x=l, --------]
10000000
--- d: Stress ------------------------------
2
3*kg*m
[|M(x=l)|, -------]
2
5*s
2000000*kg
[sig_max, ----------]
2
3*m*s
--- e: --------------------------------------
m
[x^*, --]
15
--- f: Plot ---------------------------------
