<jupyter_start><jupyter_text>Conservative SDOF - Multiple Scales  - Introduces multiple time scales (Homogenation)- Treate damped systems easier then L-P- Built-in stability Introduce new independent time variables$$\begin{gather*}    T_n = \epsilon^n t\end{gather*}$$and $$\begin{align*}    \frac{d}{dt} &= \frac{\partial}{\partial T_0}\frac{dT_0}{dt} + \frac{\partial}{\partial T_1}\frac{dT_1}{dt} +  \frac{\partial}{\partial T_2}\frac{dT_2}{dt}  + \cdots\\    &= \frac{\partial}{\partial T_0} + \epsilon \frac{\partial}{\partial T_1} + \epsilon^2 \frac{\partial}{\partial T_2} + \cdots\\    &= D_0 + \epsilon D_1 + \epsilon^2 D_2 + \cdots\end{align*}$$$$\begin{align*}    \frac{d^2}{dt^2} &= \left( D_0 + \epsilon D_1 + \epsilon^2 D_2 + \cdots \right)^2\end{align*}$$Introducing the Expansion for $x(t)$$$\begin{align*}    x(t) &= x_0(T_0,T_1,T_2,\cdots) + \epsilon x_1(T_0,T_1,T_2,\cdots) + \epsilon^2(T_0,T_1,T_2,\cdots) + \epsilon^3(T_0,T_1,T_2,\cdots) + O(\epsilon^4) \end{align*}$$<jupyter_code>import sympy as sp
from sympy.simplify.fu import TR0, TR7, TR8, TR11
from math import factorial
# Functions for multiple scales 

# Function for Time operator 
def Dt(f, n, Ts, e=sp.Symbol('epsilon')):
    if n==1:
        return sp.expand(sum([e**i * sp.diff(f, T_i) for i, T_i in enumerate(Ts)]))
    return Dt(Dt(f, 1, Ts, e), n-1, Ts, e)

def collect_epsilon(f, e=sp.Symbol('epsilon')):
    N = sp.degree(f, e)
    f_temp = f
    collected_dict = {}
    for i in range(N, 0, -1):
        collected_term = f_temp.coeff(e**i)
        collected_dict[e**i] = collected_term
        delete_terms = sp.expand(e**i * collected_term)
        f_temp -= delete_terms
    collected_dict[e**0] = f_temp
    return collected_dict
N = 3

f = sp.Function('f')
t = sp.Symbol('t', real=True)

# Define the symbolic parameters
epsilon = sp.symbols('epsilon')

T_i = sp.symbols('T_(0:' + str(N) + ')', real=True)
alpha_i = sp.symbols('alpha_(2:' + str(N+1) + ')', real=True)
omega0 = sp.Symbol('omega_0', real=True)

# x0 = sp.Function('x_0')(*T_i)
x1 = sp.Function('x_1')(*T_i)
x2 = sp.Function('x_2')(*T_i)
x3 = sp.Function('x_3')(*T_i)

# Expansion for x(t)
x_e = epsilon*x1 + epsilon**2 * x2 + epsilon**3 * x3
x_e
# Derivatives with time operators
xd = Dt(x_e, 1, T_i, epsilon)
xdd = Dt(x_e, 2, T_i, epsilon)

# EOM
EOM = xdd + sp.expand(omega0**2 * x_e) + sp.expand(sum([alpha_i[i-2] * x_e**i for i in range(2,N+1)]))
EOM
# Ordered Equations by epsilon 
epsilon_Eq = collect_epsilon(EOM)
epsilon0_Eq = sp.Eq(epsilon_Eq[epsilon**0], 0)
epsilon0_Eq
epsilon1_Eq = sp.Eq(epsilon_Eq[epsilon**1], 0)
epsilon1_Eq
epsilon2_Eq = sp.Eq(epsilon_Eq[epsilon**2], 0)
epsilon2_Eq
epsilon3_Eq = sp.Eq(epsilon_Eq[epsilon**3], 0)
epsilon3_Eq
# Find the solution for epsilon-1
A = sp.Function('A')(*T_i[1::])
x1_sol = A * sp.exp(sp.I * omega0 * T_i[0]) + sp.conjugate(A) * sp.exp(-sp.I * omega0 * T_i[0])
x1_sol
# Update the epsilon-2 equation
epsilon2_Eq = epsilon2_Eq.subs(x1, x1_sol).doit()
epsilon2_Eq = sp.expand(epsilon2_Eq)
epsilon2_Eq<jupyter_output><empty_output><jupyter_text>The secular terms will be cancelled out by $$\begin{gather*}    D_1 A = 0\end{gather*}$$<jupyter_code>epsilon2_Eq = epsilon2_Eq.subs(sp.diff(A, T_i[1]), 0)
epsilon2_Eq<jupyter_output><empty_output><jupyter_text>The particular solution of $x_2$ is $$\begin{gather*}    x_2 = \frac{\alpha_2 A^2}{3 \omega_0^2} e^{2i\omega_0 T_0} - \frac{\alpha_2 }{\omega^2_0}A\overline{A} + cc\end{gather*}$$<jupyter_code>x2_p = alpha_i[0] * A**2 / 3/omega0**2 * sp.exp(2*sp.I*omega0*T_i[0]) - alpha_i[0]/omega0**2 * A * sp.conjugate(A) 
x2_p
epsilon3_Eq = epsilon3_Eq.subs([
    (sp.diff(A, T_i[1]), 0), (x1, x1_sol), (x2, x2_p)
]).doit()
epsilon3_Eq = sp.expand(epsilon3_Eq)
epsilon3_Eq = epsilon3_Eq.subs(sp.diff(A, T_i[1], 2), 0)
epsilon3_Eq<jupyter_output><empty_output><jupyter_text>The to cancel out the secular term we let $$\begin{gather*}    2i\omega_0 D_2 A + \dfrac{9\alpha_3 \omega_0^2 - 10\alpha_2^2 }{3\omega_0^2}A^2\overline{A} = 0\end{gather*}$$Question: What if the secular terms arising from $i\omega_0$ and $-i \omega_0$ are handled together - do we get a single real equation?Substitute the polar $A$$$\begin{gather*}    A = \dfrac{1}{2}a e^{i\beta}\end{gather*}$$<jupyter_code>x3_sec = sp.Eq(2*sp.I*omega0*sp.diff(A, T_i[2]) + (9*alpha_i[1]*omega0**2 - 10*alpha_i[0]**2)/3/omega0**2 * A**2 * sp.conjugate(A), 0)

a = sp.Symbol('a', real=True)
beta = sp.Symbol('beta', real=True)

temp = x3_sec.subs(A, a*sp.exp(sp.I * beta)/2)
temp
temp = sp.expand(temp)
temp_im = sp.im(temp.lhs)
temp_im
temp_re = sp.re(temp.lhs)
temp_re<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19150779896013864, 'fraction_numerical': 0.04224436741767764, 'mean_word_length': 4.778473091364205, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '15047', 'license': 'MIT', 'n_tokens_mistral': 2053, 'n_tokens_neox': 2011, 'n_words': 387, 'path': 'notebooks/multiple_scales.ipynb', 'repo_name': 'smallpondtom/pNLsys', 'size': '4616'}