Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ def test_quadroots_1():
assert (np.abs(roots[0] - x1_exact) < 1e-14) and (np.abs(roots[1] - x2_exact)) < 1e-14

def test_chebD_1():
pass
n=2
exact = [[ 1.5, -2.0, 0.5], [ 0.5, 0.0, -0.5], [-0.5, 2.0, -1.5]]
diffMatrix, grid = ch.chebD(n)
checkArr = diffMatrix - exact
assert(np.all(checkArr < 1e-14))
15 changes: 13 additions & 2 deletions utils/chebutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

def chebD(n):
"""
Hint: https://people.maths.ox.ac.uk/trefethen/book.pdf, Chapter 6, pages
51-55.
Computes a spectral differentiation matrix and Chebysev grid

Parameters
----------
n: <int>
An integer defining the number of grid points (n+1)

Returns
-------
D: (n+1)x(n+1) matrix
differentiation matrix
x: (n+1)-d array
Chebysev grid
"""
if n == 0:
x = 1; D = 0; w = 0
Expand Down
4 changes: 2 additions & 2 deletions utils/quadroots.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def quadroots(a, b, c):
Roots of the equation.
"""

x1 = (-b + np.sqrt(b**2 - 4*a*c))/2*a
x2 = (-b - np.sqrt(b**2 - 4*a*c))/2*a
x1 = (-b + np.sqrt(b**2 - 4*a*c))/(2*a)
x2 = (-b - np.sqrt(b**2 - 4*a*c))/(2*a)

return (x1, x2)