assignment Link to heading
theory Link to heading
- The 1-d wave equation is $$\tag{1} \frac{\partial^2 u}{\partial t^2} = c^2 \frac{\partial^2 u}{\partial x^2} $$ with displacement $u$, time $t$, velocity $c$, dan position $x$ (Dawkins, 2022).
- A function of two variables $u(x, y)$ can be represented as product of two functions with single variables $$\tag{2} u(x, t) = a(x) \ b(t), $$ which is known as separation of variables (Dawkins, 2022).
- Eigen value problem $$\tag{3} \mathbf{M}\mathbf{X} = \lambda \mathbf{X}, $$ that will be applied to second order differential equation (Salih, 2016).
substitution Link to heading
- Substitute (2) to (1) will give $$ \begin{array}{rcl} \displaystyle a \frac{d^2 b}{dt^2} & = & \displaystyle c^2 b \frac{d^2 a}{dx^2} \newline \newline \displaystyle \frac1b \frac{d^2 b}{dt^2} & = & \displaystyle c^2 \frac1a \frac{d^2 a}{dx^2}, \end{array} $$ and choose both side is $-\omega^2$.
left side Link to heading
$$\tag{4} \begin{array}{rcl} \displaystyle \frac1b \frac{d^2 b}{dt^2} & = & -\omega^2 \newline \newline \displaystyle \frac{d^2 b}{dt^2} & = & -\omega^2 b. \end{array} $$
right side Link to heading
$$\tag{5} \begin{array}{rcl} \displaystyle c^2 \frac1a \frac{d^2 a}{dx^2} & = & -\omega^2 \newline \newline \displaystyle \frac{d^2 a}{dx^2} & = & \displaystyle -\frac{\omega^2}{c^2} a \newline \newline \displaystyle \frac{d^2 a}{dx^2} & = & \displaystyle -k^2 a. \end{array} $$
fdm x Link to heading
$$\tag{6} \begin{array}{rcl} \displaystyle \frac{ a_{i-1,j} - 2a_{i,j} + a_{i+1,j} }{h^2} & = & - k^2 a_{i,j} \newline \newline a_{i-1,j} - 2a_{i,j} + a_{i+1,j} & = & - h^2 k^2 a_{i,j} \newline \newline a_{i-1,j} - 2a_{i,j} + a_{i+1,j} & = & - l^2 a_{i,j} \end{array} $$
With boundary condition $a_1 = 0$ and $a_n = 0$ where $n$ is number of data.
bvp Link to heading
- (5) will be $$\tag{7} \left[ \begin{matrix} 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \newline 1 & -2 & 1 & 0 & 0 & 0 & 0 & 0 \newline 0 & 1 & -2 & 1 & 0 & 0 & 0 & 0 \newline 0 & 0 & 1 & -2 & 1 & 0 & 0 & 0 \newline 0 & 0 & 0 & 1 & -2 & 1 & 0 & 0 \newline 0 & 0 & 0 & 0 & 1 & -2 & 1 & 0 \newline 0 & 0 & 0 & 0 & 0 & 1 & -2 & 1 \newline 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \newline \end{matrix} \right] \left[ \begin{matrix} a_1 \newline a_2 \newline a_3 \newline a_4 \newline a_5 \newline a_6 \newline a_7 \newline a_8 \newline \end{matrix} \right] = -l^2 \left[ \begin{matrix} a_1 \newline a_2 \newline a_3 \newline a_4 \newline a_5 \newline a_6 \newline a_7 \newline a_8 \newline \end{matrix} \right] $$ for $n = 8$.
- It turns into an eigen value problem.
code Link to heading
import math
import numpy as np
from numpy.linalg import eig
xmin = 0
xmax = 1
h = 0.01
N = int((xmax - xmin) / h + 1)
x = [round(xmin + i*h, 2) for i in range(N)]
print("h =", h)
print("N =", N)
print("x =", x)
print()
M = np.zeros((N, N))
for i in range(1, N-1):
M[i][i-1] = 1
M[i][i] = -2
M[i][i+1] = 1
M[0][0] = 0
M[N-1][N-1] = 0
print("M =")
for i in M:
for j in i:
#print(j.round(2), end='\t')
pass
#print()
pass
print()
w, v = eig(M)
print("E=val")
for i in w:
print(round(i, 4))
print()
ii = 0
for i in range(N):
print("label: \"E-val = ", round(w[ii], 3), "\",", sep='')
print("data: [")
vj = v[:, i]
jj = 0
for j in vj:
print("\t{x: ", end='')
print(x[jj], end=', ')
print("y:", j.round(3), end='')
print("},")
jj += 1
print("],")
print()
ii += 1
- Result
h = 0.01
N = 101
x = [0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]
M =
E=val
-3.999
-3.9961
-3.9911
-3.9842
-3.9754
-3.9646
-3.9518
-3.9372
-3.8355
-3.8596
-3.8818
-3.8097
-3.782
-3.7526
-3.9021
-3.7215
-3.5803
-3.618
-3.541
-3.5002
-3.6542
-3.4579
-3.4142
-3.3691
-3.9206
-3.2258
-3.1756
-3.1242
-3.0717
-3.2748
-3.0181
-2.9635
-2.908
-2.6775
-2.7362
-2.7943
-2.618
-2.558
-2.4974
-0.001
-0.0039
-0.0089
-0.0158
-0.0246
-2.4363
-0.0354
-0.0482
-2.3748
-0.0628
-0.0979
-0.1182
-0.1404
-0.1645
-2.1256
-2.1882
-2.2507
-2.0628
-0.1903
-2.0
-1.9372
-0.218
-0.2474
-1.8744
-0.2785
-1.442
-1.5026
-1.5637
-1.382
-0.4197
-0.459
-0.4998
-0.9283
-0.8758
-1.3225
-0.8244
-2.3129
-0.9819
-0.5858
-0.5421
-1.0365
-0.7742
-0.3458
-0.6309
-1.8118
-1.6252
-1.2638
-1.092
-2.8516
-0.382
-3.3226
-3.6887
-0.7252
-1.2057
-1.7493
-1.6871
-1.1484
-0.6774
-0.0794
-0.3113
0.0
0.0