From 39c84294d02c681ab8788e74d578ee0509933053 Mon Sep 17 00:00:00 2001 From: StefanoFochesatto Date: Tue, 2 Sep 2025 06:37:58 -0800 Subject: [PATCH 1/4] fixed bug in test --- tests/test_utils.py | 4 ++-- utils/quadroots.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index d5faed3..f839793 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -7,8 +7,8 @@ def test_quadroots_1(): b = -5.0 c = 2.0 roots = qr.quadroots(a, b, c) - x1_exact = 2.0 - x2_exact = 0.5 + x1_exact = 8.0 + x2_exact = 2.0 assert (np.abs(roots[0] - x1_exact) < 1e-14) and (np.abs(roots[1] - x2_exact)) < 1e-14 def test_chebD_1(): diff --git a/utils/quadroots.py b/utils/quadroots.py index 460f2b1..8b1e0ee 100644 --- a/utils/quadroots.py +++ b/utils/quadroots.py @@ -24,4 +24,4 @@ def quadroots(a, b, c): 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) + return (x1, x2) \ No newline at end of file From 61838c7117e4261429625f5cdf34ec64f7071412 Mon Sep 17 00:00:00 2001 From: StefanoFochesatto Date: Tue, 2 Sep 2025 06:53:29 -0800 Subject: [PATCH 2/4] added docstring --- utils/chebutils.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/utils/chebutils.py b/utils/chebutils.py index 0d7e38a..b05af72 100644 --- a/utils/chebutils.py +++ b/utils/chebutils.py @@ -2,8 +2,19 @@ def chebD(n): """ - Hint: https://people.maths.ox.ac.uk/trefethen/book.pdf, Chapter 6, pages - 51-55. + Computes the Chebyshev differentiation matrix and grid points in [-1, 1]. + + Parameters + ---------- + n: int + Dimension of the chebyshev differentiation matrix. + + Returns + ------- + D: n+1 x n+1 ndarray + Chebyshev differentiation matrix. + x: n+1 ndarray + Chebyshev grid points in [-1, 1]. """ if n == 0: x = 1; D = 0; w = 0 From b295d52aa30266c3f73581bb26cc2762eec720e9 Mon Sep 17 00:00:00 2001 From: StefanoFochesatto Date: Tue, 2 Sep 2025 07:30:26 -0800 Subject: [PATCH 3/4] fix docstring --- .history/utils/chebutils_20250902072910.py | 33 ++++++++++++++++++++++ .history/utils/chebutils_20250902073016.py | 33 ++++++++++++++++++++++ utils/chebutils.py | 2 +- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 .history/utils/chebutils_20250902072910.py create mode 100644 .history/utils/chebutils_20250902073016.py diff --git a/.history/utils/chebutils_20250902072910.py b/.history/utils/chebutils_20250902072910.py new file mode 100644 index 0000000..b05af72 --- /dev/null +++ b/.history/utils/chebutils_20250902072910.py @@ -0,0 +1,33 @@ +import numpy as np + +def chebD(n): + """ + Computes the Chebyshev differentiation matrix and grid points in [-1, 1]. + + Parameters + ---------- + n: int + Dimension of the chebyshev differentiation matrix. + + Returns + ------- + D: n+1 x n+1 ndarray + Chebyshev differentiation matrix. + x: n+1 ndarray + Chebyshev grid points in [-1, 1]. + """ + if n == 0: + x = 1; D = 0; w = 0 + else: + a = np.linspace(0.0, np.pi, n+1) + x = np.cos(a) + b = np.ones_like(x) + b[0] = 2; b[-1] = 2 + d = np.ones_like(b) + d[1::2] = -1 + c = b*d + X = np.outer(x, np.ones(n+1)) + dX = X - X.T + D = np.outer(c, 1/c) / (dX + np.identity(n+1)) + D = D - np.diag(D.sum(axis=1)) + return D, x diff --git a/.history/utils/chebutils_20250902073016.py b/.history/utils/chebutils_20250902073016.py new file mode 100644 index 0000000..80efe9e --- /dev/null +++ b/.history/utils/chebutils_20250902073016.py @@ -0,0 +1,33 @@ +import numpy as np + +def chebD(n): + """ + Computes the Chebyshev differentiation matrix and grid points in [-1, 1]. + + Parameters + ---------- + n: int + Specify n + 1 dimension of the chebyshev differentiation matrix. + + Returns + ------- + D: n+1 x n+1 ndarray + Chebyshev differentiation matrix. + x: n+1 ndarray + Chebyshev grid points in [-1, 1]. + """ + if n == 0: + x = 1; D = 0; w = 0 + else: + a = np.linspace(0.0, np.pi, n+1) + x = np.cos(a) + b = np.ones_like(x) + b[0] = 2; b[-1] = 2 + d = np.ones_like(b) + d[1::2] = -1 + c = b*d + X = np.outer(x, np.ones(n+1)) + dX = X - X.T + D = np.outer(c, 1/c) / (dX + np.identity(n+1)) + D = D - np.diag(D.sum(axis=1)) + return D, x diff --git a/utils/chebutils.py b/utils/chebutils.py index b05af72..80efe9e 100644 --- a/utils/chebutils.py +++ b/utils/chebutils.py @@ -7,7 +7,7 @@ def chebD(n): Parameters ---------- n: int - Dimension of the chebyshev differentiation matrix. + Specify n + 1 dimension of the chebyshev differentiation matrix. Returns ------- From a0d662513e29e28406e2b1470eded9a0ff84ff0e Mon Sep 17 00:00:00 2001 From: StefanoFochesatto Date: Tue, 2 Sep 2025 07:31:13 -0800 Subject: [PATCH 4/4] fix docstring --- .history/utils/chebutils_20250902072910.py | 33 ---------------------- .history/utils/chebutils_20250902073016.py | 33 ---------------------- 2 files changed, 66 deletions(-) delete mode 100644 .history/utils/chebutils_20250902072910.py delete mode 100644 .history/utils/chebutils_20250902073016.py diff --git a/.history/utils/chebutils_20250902072910.py b/.history/utils/chebutils_20250902072910.py deleted file mode 100644 index b05af72..0000000 --- a/.history/utils/chebutils_20250902072910.py +++ /dev/null @@ -1,33 +0,0 @@ -import numpy as np - -def chebD(n): - """ - Computes the Chebyshev differentiation matrix and grid points in [-1, 1]. - - Parameters - ---------- - n: int - Dimension of the chebyshev differentiation matrix. - - Returns - ------- - D: n+1 x n+1 ndarray - Chebyshev differentiation matrix. - x: n+1 ndarray - Chebyshev grid points in [-1, 1]. - """ - if n == 0: - x = 1; D = 0; w = 0 - else: - a = np.linspace(0.0, np.pi, n+1) - x = np.cos(a) - b = np.ones_like(x) - b[0] = 2; b[-1] = 2 - d = np.ones_like(b) - d[1::2] = -1 - c = b*d - X = np.outer(x, np.ones(n+1)) - dX = X - X.T - D = np.outer(c, 1/c) / (dX + np.identity(n+1)) - D = D - np.diag(D.sum(axis=1)) - return D, x diff --git a/.history/utils/chebutils_20250902073016.py b/.history/utils/chebutils_20250902073016.py deleted file mode 100644 index 80efe9e..0000000 --- a/.history/utils/chebutils_20250902073016.py +++ /dev/null @@ -1,33 +0,0 @@ -import numpy as np - -def chebD(n): - """ - Computes the Chebyshev differentiation matrix and grid points in [-1, 1]. - - Parameters - ---------- - n: int - Specify n + 1 dimension of the chebyshev differentiation matrix. - - Returns - ------- - D: n+1 x n+1 ndarray - Chebyshev differentiation matrix. - x: n+1 ndarray - Chebyshev grid points in [-1, 1]. - """ - if n == 0: - x = 1; D = 0; w = 0 - else: - a = np.linspace(0.0, np.pi, n+1) - x = np.cos(a) - b = np.ones_like(x) - b[0] = 2; b[-1] = 2 - d = np.ones_like(b) - d[1::2] = -1 - c = b*d - X = np.outer(x, np.ones(n+1)) - dX = X - X.T - D = np.outer(c, 1/c) / (dX + np.identity(n+1)) - D = D - np.diag(D.sum(axis=1)) - return D, x