assignment1.dg1_high_prec module¶
Helpers to use assignment1.dg1
with high-precision numbers.
High-precision is achieved by using mpmath
.
-
class
assignment1.dg1_high_prec.
HighPrecProvider
[source]¶ Bases:
object
High-precision replacement for
assignment1.dg1.MathProvider
.Implements interfaces that are essentially identical (at least up to the usage in
dg1
) as those provided by NumPy.All matrices returned are
numpy.ndarray
withmpmath.mpf
as the data type and all matrix inputs are assumed to be of the same form.-
static
linspace
(start, stop, num=50)[source]¶ Linearly spaced points.
Points are computed with
mpmath.linspace()
but the output (alist
) is converted back to anumpy.ndarray
.
-
classmethod
solve
(left_mat, right_mat)[source]¶ Solve
Ax = b
forx
.A
is given byleft_mat
andb
byright_mat
.This method seeks to mirror
mpmath.matrices.linalg.LinearAlgebraMethods.lu_solve()
, which usesmpmath.matrices.linalg.LinearAlgebraMethods.LU_decomp()
,mpmath.matrices.linalg.LinearAlgebraMethods.L_solve()
andmpmath.matrices.linalg.LinearAlgebraMethods.U_solve()
. Due to limitations ofmpmath
we use modified helpers to accomplish the upper- and lower-triangular solves. We also cache the LU-factorization for future uses.It’s worth pointing out that
numpy.linalg.solve()
works in exactly this fashion. From the C source there is alapack_func
that gets defined and is eventually used in Python asgufunc
. Notice that thelapack_func
isdgesv
for doubles. Checking the LAPACK docs verifies thedgesv
does an LU and then two triangular solves.
-
static
-
assignment1.dg1_high_prec.
gauss_lobatto_points
(start, stop, num_points)[source]¶ Get the node points for Gauss-Lobatto quadrature.
Rather than using the optimizations in
dg1.gauss_lobatto_points()
, this usesmpmath
utilities directly to find the roots of \(P_n'(x)\) (where \(n\) is equal tonum_points - 1
).Parameters: - start (
mpmath.mpf
(orfloat
)) – The beginning of the interval. - stop (
mpmath.mpf
(orfloat
)) – The end of the interval. - num_points (int) – The number of points to use.
Return type: Returns: 1D array, the interior quadrature nodes.
- start (