Functions to take spectral derivatives with the Chebyshev and Fourier bases
Project description
Spectral Derivatives
This repository is home to Python code that can take spectral derivatives with the Chebyshev basis or the Fourier basis, based on some pretty elegant, deep math. It's useful any time you want to take a derivative numerically, such as for doing PDE simulations.
Installation and Usage
The package is a single module containing derivative functions. To install, execute:
python3 -m pip install spectral-derivatives
or from the source code
python3 -m pip install .
You should now be able to
>>> from specderiv import *
>>> import numpy as np
>>>
>>> x_n = np.cos(np.arange(21) * np.pi / 20) # cosine-spaced, includes last point
>>> y_n = np.sin(x_n) # can be periodic or aperiodic on domain [a, b]
>>> dy_n = cheb_deriv(y_n, x_n, 1)
>>>
>>> th_n = np.arange(20) * 2*np.pi / 20 # equispaced, excludes last point
>>> y_n = np.sin(th_n) # must be periodic on domain [a, b)
>>> dy_n = fourier_deriv(y_n, th_n, 1)
For further usage examples, including in higher dimension, see the Jupyter notebooks: Chebyshev and Fourier.
Note that for accurate results you'll need to use equispaced samples on an open periodic interval for fourier and cosine-spaced points for chebyshev. For examples which use arbitrary domains, see this notebook.
References
- Trefethen, N., 2000, Spectral Methods in Matlab, https://epubs.siam.org/doi/epdf/10.1137/1.9780898719598.ch8
- Johnson, S., 2011, Notes on FFT-based differentiation, https://math.mit.edu/~stevenj/fft-deriv.pdf
- Kutz, J.N., 2023, Data-Driven Modeling & Scientific Computation, Ch. 11, https://faculty.washington.edu/kutz/kutz_book_v2.pdf
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spectral_derivatives-0.7.1.tar.gz.
File metadata
- Download URL: spectral_derivatives-0.7.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e366ac5bcbf6425b8f83fe70305d7d9f91c797f050e52852e8669f0bf911126
|
|
| MD5 |
b69b4c110ea24a6f3e88a66dfb17f971
|
|
| BLAKE2b-256 |
aba0abd08b9073e622346a3f99ae3ec40be3e24cdd6de12a58f2fca533e2f332
|
File details
Details for the file spectral_derivatives-0.7.1-py3-none-any.whl.
File metadata
- Download URL: spectral_derivatives-0.7.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01a1f5680c5eaf2744813f633e6ad9d868e11c8b9d53857df0cd402c7ffd2bc6
|
|
| MD5 |
cb240b860f72e06e8095139c0e40fafb
|
|
| BLAKE2b-256 |
bf148468ae83ebe4c4aac3e0e9c02c25a4b920bd82c90029755743b543c50c62
|