assignment1.dg1_symbolic module

Symbolic helper for assignment1.dg1.

Provides exact values for stiffness and mass matrices using symbolic algebra.

For example, assignment1.dg1 previously used pre-computed mass and stiffness matrices from this module. These were created using evenly spaced points on \(\left[0, 1\right]\) for small \(p\). These values can be verified by find_matrices_symbolic() below.

assignment1.dg1_symbolic.find_matrices_symbolic(p_order, start=0, stop=1, x_vals=None)[source]

Find mass and stiffness matrices using symbolic algebra.

We do this on the reference interval \(\left[0, 1\right]\) with the evenly spaced points

\[x_0 = 0, x_1 = 1/p, \ldots, x_p = 1\]

and compute the polynomials \(\varphi_j(x)\) such that \(\varphi_j\left(x_i\right) = \delta_{ij}\). Since we are using symbolic rationals numbers, we do this directly by inverting the Vandermonde matrix \(V\) such that

\[\begin{split}\left[ \begin{array}{c c c c} 1 & x_0 & \cdots & x_0^p \\ 1 & x_1 & \cdots & x_1^p \\ \vdots & & & \vdots \\ 1 & x_p & \cdots & x_p^p \end{array}\right] \left[ \begin{array}{c} c_0 \\ c_1 \\ \vdots \\ c_p \end{array}\right] = \left(\delta_{ij}\right) = I_{p + 1}\end{split}\]

Then use these to compute the mass matrix

\[M_{ij} = \int_0^1 \varphi_i(x) \varphi_j(x) \, dx\]

and the stiffness matrix

\[K_{ij} = \int_0^1 \varphi_i'(x) \varphi_j(x) \, dx\]

Some previously used precomputed values for evenly spaced points on \(\left[0, 1\right]\) are

\[\begin{split}\begin{align*} M_1 = \frac{1}{6} \left[ \begin{array}{c c} 2 & 1 \\ 1 & 2 \end{array}\right] & \qquad K_1 = \frac{1}{2} \left[ \begin{array}{c c} -1 & -1 \\ 1 & 1 \end{array}\right] \\ M_2 = \frac{1}{30} \left[ \begin{array}{c c c} 4 & 2 & -1 \\ 2 & 16 & 2 \\ -1 & 2 & 4 \end{array}\right] & \qquad K_2 = \frac{1}{6} \left[ \begin{array}{c c c} -3 & -4 & 1 \\ 4 & 0 & -4 \\ -1 & 4 & 3 \end{array}\right] \\ M_3 = \frac{1}{1680} \left[ \begin{array}{c c c c} 128 & 99 & -36 & 19 \\ 99 & 648 & -81 & -36 \\ -36 & -81 & 648 & 99 \\ 19 & -36 & 99 & 128 \end{array}\right] & \qquad K_3 = \frac{1}{80} \left[ \begin{array}{c c c c} -40 & -57 & 24 & -7 \\ 57 & 0 & -81 & 24 \\ -24 & 81 & 0 & -57 \\ 7 & -24 & 57 & 40 \end{array}\right] \end{align*}\end{split}\]

In addition, when \(p = 3\), the Gauss-Lobatto nodes

\[x_0 = -1, \; x_1 = -\frac{1}{\sqrt{5}}, \; x_2 = \frac{1}{\sqrt{5}}, \; x_4 = 1\]

are not evenly spaced for the first time. These produce

\[\begin{split}M_3 = \frac{1}{42} \left[ \begin{array}{c c c c} 6 & \sqrt{5} & -\sqrt{5} & 1 \\ \sqrt{5} & 30 & 5 & -\sqrt{5} \\ -\sqrt{5} & 5 & 30 & \sqrt{5} \\ 1 & -\sqrt{5} & \sqrt{5} & 6 \end{array}\right]\end{split}\]

and

\[\begin{split}K_3 = \frac{1}{24} \left[ \begin{array}{c c c c} -12 & -5 & -5 & -2 \\ 5 & 0 & 0 & -5 \\ 5 & 0 & 0 & -5 \\ 2 & 5 & 5 & 12 \end{array}\right] + \frac{\sqrt{5}}{24} \left[ \begin{array}{c c c c} 0 & -5 & 5 & 0 \\ 5 & 0 & -10 & 5 \\ -5 & 10 & 0 & -5 \\ 0 & -5 & 5 & 0 \end{array}\right]\end{split}\]
Parameters:
  • p_order (int) – The degree of precision for the method.
  • start (sympy.core.expr.Expr) – (Optional) The beginning of the interval. Defaults to 0.
  • stop (sympy.core.expr.Expr) – (Optional) The end of the interval. Defaults to 1.
  • x_vals (list) – (Optional) The list of \(x\)-values to use. If not given, defaults to p_order + 1 evenly spaced points on \(\left[0, 1\right]\).
Return type:

tuple

Returns:

Pair of mass and stiffness matrices, square sympy.Matrix with rows/columns equal to p_order + 1.

assignment1.dg1_symbolic.get_symbolic_vandermonde(p_order, x_vals=None)[source]

Get symbolic Vandermonde matrix of evenly spaced points.

Parameters:
  • p_order (int) – The degree of precision for the method.
  • x_vals (list) – (Optional) The list of \(x\)-values to use. If not given, defaults to p_order + 1 evenly spaced points on \(\left[0, 1\right]\).
Return type:

tuple

Returns:

Pair of vector of powers of \(x\) and Vandermonde matrix. Both are type sympy.Matrix, the x_vec is a row vector with p_order + 1 columns and the Vandermonde matrix is square of dimension p_order + 1.