And we get \begin{equation} \mathbf{A} \frac{\partial^2 \overrightarrow{a}}{\partial t^2} + \gamma \mathbf{B} \frac{\partial \overrightarrow{a}}{\partial t} + v^2\mathbf{B}\overrightarrow{a} = 0 \end{equation}
where, $$ \mathbf{A}_{ij} = \int_0^1 \varphi_i \varphi_j(x) dx $$ and $$ \mathbf{B}_{ij} = \int_0^1 \frac{\partial \varphi_i}{\partial x} \frac{\partial \varphi_j}{\partial x}dx - \frac{\partial \varphi_i}{\partial x} \varphi_j \mid_0^1 .$$
import sympy, math
h = 10**-1
N = math.ceil(1/h) + 1
x = sympy.symbols('x')
phi = [sympy.Piecewise((0, x <= (i-1)*h), (0, x >= (i+1)*h),
((x - (i-1)*h)/h, x < i*h),
(((i+1)*h - x)/h, True))
for i in range(N)]
A = sympy.Matrix([['%.3f' %sympy.integrate(phi_i*phi_j, (x, 0, 1))
for phi_i in phi] for phi_j in phi])
B = sympy.Matrix([['%.3f' %(sympy.integrate(phi_i.diff(x)*phi_j.diff(x), (x, 0, 1)) -
(phi_i.diff(x)*phi_j).subs(x,1) + (phi_i.diff(x)*phi_j). subs(x,0))
for phi_i in phi] for phi_j in phi])
A
B
hermite = [sympy.Piecewise((0, x <= (i-1)*h), (0, x >= (i+1)*h),
((x - (i-1)*h)/h, x < i*h),
(((i+1)*h - x)/h, True))
for i in range(N)]
A_herm = sympy.Matrix([[sympy.integrate(herm_i*herm_j, (x, 0, 1))
for herm_i in hermite] for herm_j in hermite])
B_herm = sympy.Matrix([[(sympy.integrate(herm_i.diff(x)*herm_j.diff(x), (x, 0, 1)) -
(herm.diff(x)*herm_j).subs(x,1) + (herm_i.diff(x)*herm_j). subs(x,0))
for herm_i in hermite] for herm_j in hermite])