# Matplotlib compatibility patch for Pyodide
import matplotlib
if not hasattr(matplotlib.RcParams, "_get"):
matplotlib.RcParams._get = dict.get
Lesson Wednesday September 18th#
During today’s lesson you’ll work on a complex exercise on the topic of SymPy. Please ask your questions regarding the homework as well!
Exercise SymPy#
Given the following structure.
Find the normal force distribution
Given the following structure.
Find the bending moment distribution
Find the shear force distribution
Find the displacement distribution
Solution assignment 1
Given the following coordinate system:
\[N_\text{AC} = 8 x - 16 \text{ } \left(\text{ kN}\right)\]
\[N_\text{CD} = 32 \text{ } \left(\text{ kN}\right)\]
\[N_\text{DB} = -28 \text{ } \left(\text{ kN}\right)\]
Solution assignment 2
Given the following coordinate system:
\[M_\text{AB} = \cfrac{x^{3}}{2} - \cfrac{21 x^{2}}{2} + \cfrac{147 x}{4} - \cfrac{95}{4} \text{ } \left(\text{kNm}\right)\]
\[M_\text{BS} = \cfrac{x^{3}}{2} - \cfrac{21 x^{2}}{2} + \cfrac{183 x}{2} - \cfrac{595}{2} \text{ } \left(\text{kNm}\right)\]
\[M_\text{SD} = 18 x - 126 \text{ } \left(\text{kNm}\right)\]
\[M_\text{DC} = 144 - 12 x \text{ } \left(\text{kNm}\right)\]
Solution assignment 3
Given the following coordinate system:
\[V_\text{AB} = \cfrac{3 x^{2}}{2} - 21 x + \cfrac{147}{4} \text{ } \left(\text{kN}\right) \]
\[V_\text{BS} = \cfrac{3 x^{2}}{2} - 21 x + \cfrac{183}{2} \text{ } \left(\text{kN}\right)\]
\[V_\text{SD} = 18 \text{ } \left(\text{kN}\right)\]
\[V_\text{DC} = -12 \text{ } \left(\text{kN}\right)\]
Solution assignment 4
Given the following coordinate system:
\[w_\text{AB} = - \cfrac{x^{5}}{120000} + \cfrac{7 x^{4}}{24000} - \cfrac{49 x^{3}}{24000} + \cfrac{19 x^{2}}{4800} \text{ } \left(\text{m}\right)\]
\[w_\text{BS} = - \cfrac{x^{5}}{120000} + \cfrac{7 x^{4}}{24000} - \cfrac{61 x^{3}}{12000} + \cfrac{119 x^{2}}{2400} - \cfrac{73 x}{320} + \cfrac{73}{192} \text{ } \left(\text{m}\right)\]
\[w_\text{SD} = - \cfrac{x^{3}}{1000} + \cfrac{21 x^{2}}{1000} - \cfrac{20537 x}{150000} + \cfrac{7549}{25000} \text{ } \left(\text{m}\right)\]
\[w_\text{DC} = \cfrac{x^{3}}{1500} - \cfrac{3 x^{2}}{125} + \cfrac{40213 x}{150000} - \cfrac{11413}{12500} \text{ } \left(\text{m}\right)\]
If you don’t have Python and SymPy installed, click –> Live Code to activate live coding and use the cells below:
import sympy as sym
sym.init_printing()
x = sym.symbols('x')
C1, C2, C3, C4 = sym.symbols('C1 C2 C3 C4')
q =
V = sym.integrate(-q,x)+C1
M = sym.integrate(V,x)+C2
kappa = M / EI
phi = sym.integrate(kappa,x)+C3
w = sym.integrate(-phi,x)+C4
Eq1 = sym.Eq(
sol = sym.solve((Eq1,Eq2,Eq3,Eq4,Eq5,Eq6,Eq7,Eq8,Eq9,Eq10,Eq11,Eq12), (C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12))
display(sol)
M.subs(sol)
import numpy as np
import matplotlib.pyplot as plt
%config InlineBackend.figure_formats = ['svg']
def plot(w_list, x_range_list,ylabel):
plt.figure()
for i, w in enumerate(w_list):
# check if x is the only symbol in the expression
if len(w.free_symbols) > 1:
raise ValueError('The expression must be a function of x only.')
w_numpy = sym.lambdify(x, w)
x_vals = np.linspace(x_range_list[i][0], x_range_list[i][1], 100)
# if the expression is a constant, we need to make sure that it is broadcasted correctly
if isinstance(w_numpy(x_vals),float) or isinstance(w_numpy(x_vals),int):
w_numpy = np.vectorize(w_numpy)
plt.plot([x_range_list[i][0], x_range_list[i][1]],[w_numpy(x_vals),w_numpy(x_vals)])
else:
plt.plot(x_vals,w_numpy(x_vals))
plt.plot(x_vals,w_numpy(x_vals))
plt.xlabel('$x$')
plt.ylabel(ylabel)
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['left'].set_position('zero')
ax.invert_yaxis()
plot(