Skip to main content

Spectral Derivatives

Build Status Coverage Status

Documentation, How it works.

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

  1. Trefethen, N., 2000, Spectral Methods in Matlab, https://epubs.siam.org/doi/epdf/10.1137/1.9780898719598.ch8
  2. Johnson, S., 2011, Notes on FFT-based differentiation, https://math.mit.edu/~stevenj/fft-deriv.pdf
  3. Kutz, J.N., 2023, Data-Driven Modeling & Scientific Computation, Ch. 11, https://faculty.washington.edu/kutz/kutz_book_v2.pdf

Metadata

Release files for spectral-derivatives 0.7.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spectral-derivatives 0.7.3
File Size Uploaded
spectral_derivatives-0.7.3.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spectral-derivatives 0.7.3
File Interpreter ABI Platform
spectral_derivatives-0.7.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / spectral_derivatives-0.7.3.tar.gz

Download URL spectral_derivatives-0.7.3.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8d862e0bbf8576958b94ea72424068ed07f664fdb97f6be5418c829b863e09a8
BLAKE2b-256 checksum
How to use checksums
1fdb2292ef1d9d704dc8ce0943ed4278f8124214554654afa540e7e9aee0bd7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / spectral_derivatives-0.7.3-py3-none-any.whl

Download URL spectral_derivatives-0.7.3-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3107ce407b9d3fbd612139c1720368b8a69d29e1d359047b0b2f98d58dc8e68a
BLAKE2b-256 checksum
How to use checksums
afbd021ede68259bc4d6416f96f71f2bb22dc7793487424c8551b4158a647b68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

0.10

2 release files

0.9

2 release files

0.8

2 release files

0.7.4

2 release files

This release

0.7.3 This release

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page