<jupyter_start><jupyter_text>$$y'' + 2 y' + 2 y = \cos(2x)$$-------------------------$$\begin{alignedat}{0}   u=y\quad v=y'\\   \\   u'=v\\   v'=-2v-2u+\cos(2x)\end{alignedat}$$<jupyter_code>h=0.01
x = np.arange(0, 10, h)

u = np.zeros(len(x))
u[0]=0

v = np.zeros(len(x))
v[0]=0

for i in range(1,len(x)):        
    u[i] = u[i-1] + h*(v[i-1])
    v[i] = v[i-1] + h*(-2*v[i-1]-2*u[i]+np.cos(2*x[i-1]))
    

fig, ax = plt.subplots(figsize=(17,8))

ax.plot(x, u, color='blue', label="Numerical solution")

exact=-1/20*np.exp(-x)*(-5*np.exp(x)*np.sin(x)*np.sin(x) + 6*np.sin(x) - 3*np.exp(x)*np.sin(x)*np.sin(3*x) + 5*np.exp(x)*np.cos(x)*np.cos(x) - 3*np.exp(x)*np.cos(3*x)*np.cos(x) - 2*np.cos(x) - 10*np.exp(x)*np.sin(x)*np.cos(x) + np.exp(x)*np.sin(3*x)*np.cos(x) - np.exp(x)*np.sin(x)*np.cos(3*x))
ax.plot(x, exact, color='red', label="Exact solution")
 

ax.set_axisbelow(True)
ax.minorticks_on()
ax.grid(which='major', linestyle='-', linewidth=0.5, color='black', zorder=0)
ax.grid(which='minor', linestyle=':', linewidth=0.5, color='black', alpha=0.7, axis='x', zorder=0)
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(1))
ax.set_xlim(xmin=0,xmax=10)
plt.legend()<jupyter_output><empty_output><jupyter_text>$$y''+\omega^2y=0$$--------------------$$\begin{alignedat}{0}   u=y\quad v=y'\\   \\   u'=v\\   v'=-\omega^2u\end{alignedat}$$<jupyter_code>omega = 2

h=0.01
x = np.arange(0, 11, h)

u = np.zeros(len(x))
u[0]=2

v = np.zeros(len(x))
v[0]=0

for i in range(1,len(x)):        
    u[i] = u[i-1] + h*(v[i-1])
    v[i] = v[i-1] - h*(omega**2*u[i])

    
fig, ax = plt.subplots(figsize=(17,8))

ax.plot(x, u, color='blue', label="Numerical solution")
ax.plot(x, u[0]*np.cos(omega*x), color='red', label="Exact solution")

ax.set_axisbelow(True)
ax.minorticks_on()
ax.grid(which='major', linestyle='-', linewidth=0.5, color='black', zorder=0)
ax.grid(which='minor', linestyle=':', linewidth=0.5, color='black', alpha=0.7, axis='x', zorder=0)
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(1))
ax.set_xlim(xmin=0,xmax=10)
plt.legend()<jupyter_output><empty_output><jupyter_text>$$my''+by'+ky=0$$--------------------$$\begin{alignedat}{0}   u=y\quad v=y'\\   \\   u'=v\\   v'=-\frac{bv+ku}{m}\end{alignedat}$$<jupyter_code>m = 0.7
k = 19.92
b = 0.7

h=0.01
x = np.arange(0, 11, h)

u = np.zeros(len(x))
u[0]=10

v = np.zeros(len(x))
v[0]=0

for i in range(1,len(x)):        
    u[i] = u[i-1] + h*(v[i-1])
    v[i] = v[i-1] - h*((b*v[i-1]+k*u[i])/m)

    
fig, ax = plt.subplots(figsize=(17,8))

ax.plot(x, u, color='blue', label="Numerical solution")
ax.plot(x, u[0]*np.exp(-0.5*x)*(0.0941435*np.sin(5.31104*x)+np.cos(5.31104*x)), color='red', label="Exact solution")

ax.set_axisbelow(True)
ax.minorticks_on()
ax.grid(which='major', linestyle='-', linewidth=0.5, color='black', zorder=0)
ax.grid(which='minor', linestyle=':', linewidth=0.5, color='black', alpha=0.7, axis='x', zorder=0)
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(1))
ax.set_xlim(xmin=0,xmax=10)
plt.legend()<jupyter_output><empty_output><jupyter_text>$$\begin{alignedat}{0}    m_1 x_1'' + b_1 x_1' + k_1 (x_1 - L_1) - k_2 (x_2 - x_1 - L_2) = 0\\    \\    m_2 x_2'' + b_2 x_2' + k_2 (x_2 - x_1 - L_2) = 0\end{alignedat}$$--------------------$$\begin{alignedat}{0}   y_1 = x_1'\quad y_2 = x_2'\\   \\   x_1' = y_1\\   \\   y_1' = \frac{-b_1 y_1 - k_1 (x_1 - L_1) + k_2 (x_2 - x_1 - L_2)}{m_1}\\   \\   x_2' = y_2\\   \\   y_2' = \frac{-b_2 y_2 - k_2 (x_2 - x_1 - L_2)}{m_2}\end{alignedat}$$<jupyter_code># Masses:
m1 = 1.0
m2 = 1.5

# Spring constants
k1 = 8.0
k2 = 40.0

# Natural lengths
L1 = 0.5
L2 = 1.0

# Friction coefficients
b1 = 0.8
b2 = 0.5


h=0.0001
t = np.arange(0, 10, h)

x1 = np.zeros(len(t))
y1 = np.zeros(len(t))
x2 = np.zeros(len(t))
y2 = np.zeros(len(t))

x1[0]=0.5
y1[0]=0
x2[0]=2.25
y2[0]=0

for i in range(1,len(t)):        
    x1[i] = x1[i-1] + h*(y1[i-1])
    y1[i] = y1[i-1] + h*((-b1 * y1[i-1] - k1 * (x1[i-1] - L1) + k2 * (x2[i-1] - x1[i-1] - L2)) / m1)
    x2[i] = x2[i-1] + h*(y2[i-1])
    y2[i] = y2[i-1] + h*((-b2 * y2[i-1] - k2 * (x2[i-1] - x1[i-1] - L2)) / m2)


fig, ax = plt.subplots(figsize=(17,8))

ax.plot(t, x1, color='blue', label=r"$x_1$")
ax.plot(t, x2, color='green', label=r"$x_2$")

ax.set_axisbelow(True)
ax.minorticks_on()
ax.grid(which='major', linestyle='-', linewidth=0.5, color='black', zorder=0)
ax.grid(which='minor', linestyle=':', linewidth=0.5, color='black', alpha=0.7, axis='x', zorder=0)
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(1))
ax.set_xlim(xmin=0,xmax=10)
plt.legend()<jupyter_output><empty_output><jupyter_text>Van der Pol oscillator$$\frac{d^2x}{dt^2} - \mu\left(1-x^2\right )\frac{dx}{dt} + x-A \sin(\omega t) = 0$$--------------------$$\begin{alignedat}{0}   \frac{dx}{dt} = y   \\   \\   \frac{dy}{dt} = \mu \left (1-x^2\right )y - x-A \sin(\omega t)\end{alignedat}$$<jupyter_code>mu = 8
a = 1.2
w = 2*3.14159/10

h=0.001
t = np.arange(0, 100, h)

x = np.zeros(len(t))
x[0]=0.5

y = np.zeros(len(t))
y[0]=0

for i in range(1,len(t)):            
    x[i] = x[i-1] + h*(y[i-1])
    y[i] = y[i-1] + h*(mu*(1-x[i-1]**2)*y[i-1] - x[i-1] - a*np.sin(w*t[i]))
    

fig, ax = plt.subplots(figsize=(17,8))

ax.plot(t, x, color='blue')

ax.set_axisbelow(True)
ax.minorticks_on()
ax.grid(which='major', linestyle='-', linewidth=0.5, color='black', zorder=0)
ax.grid(which='minor', linestyle=':', linewidth=0.5, color='black', alpha=0.7, axis='x', zorder=0)
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(10))
ax.set_xlim(xmin=0,xmax=100)<jupyter_output><empty_output><jupyter_text>$$y''+0.01y'+ay^+-by^-=10+\lambda\sin(\mu t)$$--------------------$$\begin{alignedat}{0}   u' = v   \\   v'= 10+\lambda\sin(\mu t) -0.01v-au^++bu^-\end{alignedat}$$<jupyter_code>a = 17
b = 1
λ = 15.4
μ = 0.75

def pos(x):
    return max(x, 0)

def neg(x):
    return max(-x, 0)

h=0.1
t = np.arange(0, 100, h)

u = np.zeros(len(t))
v = np.zeros(len(t))

u[0]=1
v[0]=0

for i in range(1,len(t)):            
    u[i] = u[i-1] + h*(v[i-1])
    v[i] = v[i-1] + h*(10 + λ*np.sin(μ*t[i]) - 0.01*v[i-1] - a*pos(u[i]) + b*neg(u[i]))
    
fig, ax = plt.subplots(figsize=(17,8))

ax.plot(t, u, color='blue')

ax.set_axisbelow(True)
ax.minorticks_on()
ax.grid(which='major', linestyle='-', linewidth=0.5, color='black', zorder=0)
ax.grid(which='minor', linestyle=':', linewidth=0.5, color='black', alpha=0.7, axis='x', zorder=0)
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(10))
ax.set_xlim(xmin=0,xmax=100)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.28278940886699505, 'fraction_numerical': 0.06711822660098522, 'mean_word_length': 3.7285298398835516, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '614760', 'license': 'MIT', 'n_tokens_mistral': 3457, 'n_tokens_neox': 3278, 'n_words': 470, 'path': 'Second Order Differential Equations.ipynb', 'repo_name': 'vislupus/mathematical-modeling', 'size': '6496'}