Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complex domain problems #31

Open
piperfw opened this issue Jun 11, 2024 · 2 comments
Open

complex domain problems #31

piperfw opened this issue Jun 11, 2024 · 2 comments

Comments

@piperfw
Copy link

piperfw commented Jun 11, 2024

The docstrings of the RungeKutta solvers indicate that they can be applied in the complex domain.
However a complex initial state y0 is cast to float by the Solver class (core.py L141).
Is integration in the complex domain supported?

@maurosilber
Copy link
Collaborator

That's just because we copied the docstrings from SciPy. It doesn't seem that straightforward to directly support complex numbers. If the RHS function is already defined using complex numbers, you could wrapping as in the following example:

import nbkode
import numba
import numpy as np


@numba.njit
def complex_f(t, y):
    return -1j * y


@numba.njit
def f(t, y):
    y = y.view(np.complex_)
    dy = complex_f(t, y)
    return dy.view(np.float_)

t0 = 0
y0 = np.array([1.0 + 1.0j], dtype=np.complex_)
solver = nbkode.RungeKutta45(f, t0, y0.view(np.float_))
t, y = solver.step(n=5)
y = y.view(np.complex_)

@piperfw
Copy link
Author

piperfw commented Jun 12, 2024

Thanks! I was looking at just splitting up the equations into real and imaginary parts, but for a large complex system your wrapping will be far more convenient.

Happy to PR for the docstrings otherwise feel free to close this issue.

maurosilber added a commit that referenced this issue Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants