<jupyter_start><jupyter_text>https://lcvmwww.epfl.ch/~lcvm/dna_teaching_05_06/exercises/ex5.pdf$$E(\theta, \phi, \lambda) = \frac12 \theta^2 + \frac12(\phi - \theta)^2 + \lambda(\cos\theta + \cos\phi)$$<jupyter_code>from math import sin, cos
def energy(theta, phi, lam):
    return 0.5 * theta ** 2 + 0.5 * (phi - theta)**2 + lam * (cos(theta) + cos(phi))<jupyter_output><empty_output><jupyter_text>The equilibrium condition is given by $$0 = \frac{\partial E}{\partial \theta} = \theta + \theta - \phi - \lambda\sin\theta = 2\theta-\phi- \lambda\sin\theta,\quad  0 = \frac{\partial E}{\partial \phi} = \phi - \theta - \lambda\sin\phi$$<jupyter_code>def F(theta, phi, lam):
    return 2*theta - phi - lam * sin(theta), phi - theta - lam * sin(phi)<jupyter_output><empty_output><jupyter_text>The Jacobian of F is given by $$J = \begin{pmatrix}2-\lambda\cos(\theta) & -1\\-1 & 1-\lambda\cos\phi\end{pmatrix}$$<jupyter_code>import numpy as np
def J(theta, phi, lam):
    return np.array([[2-lam*cos(theta), -1], [-1, 1-lam*cos(phi)]])
J(0,0,0)<jupyter_output><empty_output><jupyter_text>In the case of the straight rod (\theta = \phi = 0) J(0,0,\lambda) is singular when $$\lambda^2 - 3\lambda + 1 = 0$$thus when $\lambda = \frac12(3\pm\sqrt5)$<jupyter_code>J(0,0,0.5*(3-5**.5))
J(0,0,0.5*(3+5**.5))<jupyter_output><empty_output><jupyter_text>The null spaces are spanned by $(1, \frac12(\sqrt5+1))$ and $(\frac12(\sqrt5+1), -1)$ respectively<jupyter_code>J(0,0,0.5*(3-5**.5)) @ np.array([1,0.5*(5**0.5+1)]), J(0,0,0.5*(3+5**.5)) @ np.array([0.5*(5**0.5+1), -1])<jupyter_output><empty_output><jupyter_text>StabilityThe hessian is identical to J in this case. Its eigenvalues are given by$$\mu_1\mu_2 = \det J(0,0,\lambda) = \lambda^2 - 3\lambda+1\quad\text{and}$$$$\mu_1 + \mu_2 = \operatorname{tr}J(0,0,\lambda) = 3-2\lambda$$Thus for $\lambda  \frac12(3+\sqrt5)$ the eigenvalues have the same sign, and in between they have opposite signs. For $\lambda  \frac12(3+\sqrt5)$ their sum is negative and thus they are both negative.<jupyter_code>np.linalg.eig(J(0,0,0.3))
np.linalg.eig(J(0,0,1.5))
np.linalg.eig(J(0,0,2.7))
np.linalg.eig(J(0,0,0.5*(3-5**.5)))<jupyter_output><empty_output><jupyter_text>Bifurcation Shape<jupyter_code>from sympy import *
eps, phi, the, lam, E = symbols('ε φ θ λ E')
phi_ = symbols(['φ_%d' % i for i in range(4)])
the_ = symbols(['θ_%d' % i for i in range(4)])
lam_ = symbols(['λ_%d' % i for i in range(4)])
phi_eps = sum(eps**i * phi_[i] for i in range(4))
the_eps = sum(eps**i * the_[i] for i in range(4))
lam_eps = sum(eps**i * lam_[i] for i in range(4))
the_eps
E = (the**2 + (phi-the)**2)/2 + lam*(cos(phi)+cos(the))
F1, F2 = diff(E, the), diff(E, phi)
F1_eps = F1.subs([(the, the_eps), (phi, phi_eps), (lam, lam_eps)])
F1_eps.subs(eps,0)
diff(F1_eps, eps).subs(eps, 0)
conditions = [
    diff(diff(E, x).subs([(the, the_eps), (phi, phi_eps), (lam, lam_eps)]), eps, i).subs(eps, 0) * factorial(i)
    for i in range(4)
    for x in (phi, the)
]; conditions
cond_1 = [c.subs([(the_[0], 0), (phi_[0],0), (lam_[0], (3-sqrt(5))/2)]) for c in conditions]; cond_1
from sympy.solvers.solveset import linsolve
linsolve(cond_1[:4], (the_[1], phi_[1]))

cond_2 = [c.subs([(phi_[1],1), (the_[1], (sqrt(5)-1)/2)]).simplify() for c in cond_1]
#cond_2[4] /= 2
#cond_2[5] /= (1+sqrt(5))
#cond_2[5] = cond_2[5].simplify()
cond_2
linsolve(cond_2[:6], (the_[2], phi_[2], lam_[1]))
cond_3 = [c.subs([(phi_[2],1), (the_[2], (sqrt(5)-1)/2), (lam_[1], 0)]).simplify() for c in cond_2]
cond_3
linsolve(cond_3, (the_[3], phi_[3], lam_[2]))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22965034965034964, 'fraction_numerical': 0.05818181818181818, 'mean_word_length': 4.969949916527546, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '157201', 'license': 'MIT', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1586, 'n_words': 323, 'path': 'TwoBars.ipynb', 'repo_name': 'leovt/cosserat', 'size': '3575'}