aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-06-25 15:41:19 +0800
committerAaron LI <aly@aaronly.me>2017-06-25 15:41:19 +0800
commitd55312df49ea778b0a337be26fa4383d44a1a844 (patch)
treefbaad26eca0adfc42b15837e5619c90d66afc8f0 /fg21sim
parentc1fb9dfb5ee24d32e3dde28651cedede09516501 (diff)
downloadfg21sim-d55312df49ea778b0a337be26fa4383d44a1a844.tar.bz2
solver.py: Add example for TDMAsolver()
Diffstat (limited to 'fg21sim')
-rw-r--r--fg21sim/extragalactic/clusters/solver.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/fg21sim/extragalactic/clusters/solver.py b/fg21sim/extragalactic/clusters/solver.py
index bc9a8fd..364d91c 100644
--- a/fg21sim/extragalactic/clusters/solver.py
+++ b/fg21sim/extragalactic/clusters/solver.py
@@ -22,6 +22,22 @@ def TDMAsolver(a, b, c, d):
a[i]*x[i-1] + b[i]*x[i] + c[i]*x[i+1] = d[i],
where: a[1] = c[n] = 0
+ Example
+ -------
+ >>> A = np.array([[10, 2, 0, 0],
+ [ 3, 10, 4, 0],
+ [ 0, 1, 7, 5],
+ [ 0, 0, 3, 4]], dtype=float)
+ >>> a = np.array([ 3, 1, 3], dtype=float)
+ >>> b = np.array([10, 10, 7, 4], dtype=float)
+ >>> c = np.array([ 2, 4, 5 ], dtype=float)
+ >>> d = np.array([ 3, 4, 5, 6], dtype=float)
+ >>> print(TDMAsolver(a, b, c, d))
+ [ 0.14877589 0.75612053 -1.00188324 2.25141243]
+ # compare against numpy linear algebra library
+ >>> print(np.linalg.solve(A, d))
+ [ 0.14877589 0.75612053 -1.00188324 2.25141243]
+
References
----------
[1] http://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm