In [1]:
#Pkg.add("SymPy") # Run this line the first time to install the SymPy package
using SymPy

Ex 1

$$U_S(x) = \int \frac{M(x)}{2EI} dx$$

In [2]:
@syms x, q, R1, R2, l, i, E
M1(x) = R1*x-(q*x^(2))/(2)
M2(x) = R1*x+R2*(x-l/(2))-(q*x^(2))/(2)


Out[2]:
M2 (generic function with 1 method)

Using Castigliano's second theorem, that states $$\frac{\partial U}{\partial Q_i}=q_i$$

Where $Q_i$ is genneralized forces and $q_i$ is genneralized displacements. Since there is no deflection in the two supports then the differentiated with repect to the reaction force set to zero


In [3]:
U = integrate(M1(x)^2/(2*E*i),x,0,l/2) + integrate(M2(x)^2/(2*E*i),x,l/2,l)


Out[3]:
$$\frac{R_{1}^{2} l^{3}}{48 e i} - \frac{R_{1} l^{4} q}{128 e i} + \frac{R_{2}^{2} l^{3}}{16 e i} + \frac{l^{5} q^{2}}{40 e i} - \frac{15 l^{4}}{128 e i} \left(R_{1} q + R_{2} q\right) + \frac{7 l^{3}}{96 e i} \left(2 R_{1}^{2} + 4 R_{1} R_{2} + 2 R_{2}^{2} + R_{2} l q\right) - \frac{3 l^{2}}{16 e i} \left(R_{1} R_{2} l + R_{2}^{2} l\right)$$

In [4]:
eq1 = diff(U,R1)


Out[4]:
$$\frac{R_{1} l^{3}}{24 e i} - \frac{3 R_{2} l^{3}}{16 e i} - \frac{l^{4} q}{8 e i} + \frac{7 l^{3}}{96 e i} \left(4 R_{1} + 4 R_{2}\right)$$

In [5]:
eq2= diff(U,R2)


Out[5]:
$$\frac{R_{2} l^{3}}{8 e i} - \frac{15 l^{4} q}{128 e i} + \frac{7 l^{3}}{96 e i} \left(4 R_{1} + 4 R_{2} + l q\right) - \frac{3 l^{2}}{16 e i} \left(R_{1} l + 2 R_{2} l\right)$$

In [6]:
solve([eq1,eq2], [R1, R2])


Out[6]:
\begin{equation*}\begin{cases}R_{1} & \text{=>} &\frac{11 l}{56} q\\R_{2} & \text{=>} &\frac{4 l}{7} q\\\end{cases}\end{equation*}

Super, return the same as maple

ex2

Since we would like to find the displacement in point A, we call it P1 and then later apply the relation between P and P1


In [7]:
@syms x, q, P, P1, l, i, E
M1(x) = ((l-x)*2)*P
M2(x) = ((l-x)*2)*P-P1*((1/2)*l-x)

U = integrate(M2(x)^2/(2*E*i),x,0,l/2) + integrate(M1(x)^2/(2*E*i),x,l/2,l)


Out[7]:
$$\frac{P^{2} l^{3}}{12 e i} + \frac{l^{3}}{48 e i} \left(4 P^{2} - 4 P P_{1} + P_{1}^{2}\right) - \frac{0.25 l^{2}}{e i} \left(2.0 P^{2} l - 1.5 P P_{1} l + 0.25 P_{1}^{2} l\right) + \frac{0.5 l}{e i} \left(2.0 P^{2} l^{2} - 1.0 P P_{1} l^{2} + 0.125 P_{1}^{2} l^{2}\right)$$

differentiating with respect to P1


In [8]:
eq1 = diff(U, P1)


Out[8]:
$$\frac{l^{3}}{48 e i} \left(- 4 P + 2 P_{1}\right) - \frac{0.25 l^{2}}{e i} \left(- 1.5 P l + 0.5 P_{1} l\right) + \frac{0.5 l}{e i} \left(- 1.0 P l^{2} + 0.25 P_{1} l^{2}\right)$$

Remember that P1 is equal P and substitue in the equation. So the displacement in point A isequal to


In [9]:
eq1(P1 => P) # Substitute P1 with P


Out[9]:
$$- \frac{0.166666666666667 P l^{3}}{e i}$$

ex 3


In [10]:
M1(x) = x*P
M2(x) = x*P-(x-l/(2))*3/(2)*P
U = integrate(M1(x)^2/(2*E*i),x,0,l/2) + integrate(M2(x)^2/(2*E*i), x, l/2, l*3/2)
eq1 = diff(U, P)


Out[10]:
$$\frac{P l^{3}}{8 e i}$$

Displacement in point P is found

ex 4


In [11]:
M1(x) = x*P+(q*x^(2))/(2)


Out[11]:
M1 (generic function with 1 method)

In [12]:
U = integrate(M1(x)^2/(2*E*i),x,0,l)
eq1 = diff(U, P)


Out[12]:
$$\frac{P l^{3}}{3 e i} + \frac{l^{4} q}{8 e i}$$

Rember that P is equal 0, the displacement in x=0 is


In [13]:
eq1(P=>0)


Out[13]:
$$\frac{l^{4} q}{8 e i}$$

ex 5


In [14]:
@syms M
M1(x) = M+(q*x^(2))/(2)
M2(x) = M+(q*l^(2))/(2)
U = integrate(M1(x)^2/(2*E*i),x,0,l) + integrate(M2(x)^2/(2*E*i),x,l,2l)
eq1 = diff(U, M)
# M is 0
eq1(M=>0)


Out[14]:
$$\frac{2 l^{3} q}{3 e i}$$

ex 6


In [15]:
@syms q1,q2, A, Q1, E_mod
θ = 30*((1/180)*pi)
ɛ1(x) = q1/l
ɛ2(x) = 2*q2/l
ɛ3(x) = (cos((1/4)*pi)*q1+cos((1/4)*pi)*q2)/l
U = integrate((E_mod*A*ɛ1(x)^2)/2,x,0,l) + integrate((E_mod*A*ɛ2(x)^2)/2,x,0,l/2) + integrate((E_mod*A*ɛ3(x)^2)/2,x,0,l) - Q1*q1*cos(θ)-Q1*q2*sin(θ)
eq2 = diff(U,q2)
eq1 = diff(U,q1)
solve([eq1, eq2], [q1, q2])


Out[15]:
\begin{equation*}\begin{cases}q_{1} & \text{=>} &\frac{0.547161002703171 Q_{1} l}{A E_{mod}}\\q_{2} & \text{=>} &\frac{0.0905677994593659 Q_{1} l}{A E_{mod}}\\\end{cases}\end{equation*}

ex 7


In [16]:
@syms R1
M1(x) = P1*x
M2(x) = P1*l+R1*x
M3(x) = P1*l+R1*x-2*P*(x-l)
M4(x) = P1*(l-x)+R1*l*(3)/(2)-2*P*(l)/(2)
U = integrate(M1(x)^2/(2*E*i),x,0,l) + integrate(M2(x)^2/(2*E*i),x,0,l) + 
    integrate(M3(x)^2/(2*E*i),x,l,3*l/2) + integrate(M4(x)^2/(2*E*i),x,0,l/2)
eq1 = diff(U,P1)(P1 => P)
eq2 = diff(U,R1)(P1 => P)
r1 = solve(eq2, R1)[1]


Out[16]:
$$- \frac{29 P}{108}$$

In [17]:
δ_p = eq1(R1=>r1)


Out[17]:
$$\frac{67 P l^{3}}{64 e i}$$

ex 8


In [18]:
@syms Mb, R1,R2
M1(x) = P*x
M2(x) = P*x-R1*(x-l/(2))+Mb
M3(x) = P*x-R1*(x-l/(2))-R2*(x-(3* l)/(2))+Mb
U = integrate(M1(x)^2/(2*E*i),x,0,l/2) + integrate(M2(x)^2/(2*E*i),x,l/2,l*3/2) + 
    integrate(M3(x)^2/(2*E*i),x,3/2 * l,5*l/2)
#Reaction forces is determined from eq1 and eq2
eq1 = subs(diff(U,R1),Mb, 0)
eq2 = subs(diff(U,R2),Mb, 0)
res = solve([eq1, eq2], [R1, R2])


Out[18]:
\begin{equation*}\begin{cases}R_{1} & \text{=>} &1.64285714285714 P\\R_{2} & \text{=>} &- 0.857142857142857 P\\\end{cases}\end{equation*}

In [19]:
eq3 = diff(U,P)(Mb => 0 ,res...)


Out[19]:
$$\frac{0.113095238095238 P l^{3}}{e i}$$

In [20]:
eq4 = diff(U,Mb)(Mb => 0 ,res...)


Out[20]:
$$\frac{0.142857142857143 P l^{2}}{e i}$$

In [ ]: