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

Backward in time using numbalsoda #19

Open
meysam-motaharfar opened this issue Nov 8, 2022 · 1 comment
Open

Backward in time using numbalsoda #19

meysam-motaharfar opened this issue Nov 8, 2022 · 1 comment

Comments

@meysam-motaharfar
Copy link

meysam-motaharfar commented Nov 8, 2022

Hi

I am using numblsoda to solve couples of first order differential equations. I need to solve those equations backward in time for some particular situations. I could not figure out how I can do that. I tried to use decreasing time step but it does not work as it works for solve_ivp and odeint.

for instance in this code how can I go backward in time?

from numbalsoda import lsoda_sig, lsoda, dop853
from numba import njit, cfunc
import numpy as np

@cfunc(lsoda_sig)
def rhs(t, u, du, p):
    du[0] = u[0]-u[0]*u[1]
    du[1] = u[0]*u[1]-u[1]*p[0]

funcptr = rhs.address # address to ODE function
u0 = np.array([5.,0.8]) # Initial conditions
data = np.array([1.0]) # data you want to pass to rhs (data == p in the rhs).
t_eval = np.arrange(0.0,50.0,0.1) # times to evaluate solution


usol, success = lsoda(funcptr, u0, t_eval, data = data)

I tried t_eval = np.arrange(50, 0, -0.1) but it does not work. It would be great if someone could help me to fix this issue.

@Nicholaswogan
Copy link
Owner

This is a current drawback of the code. It does not permit backwards integration right now, but it is very fixable. I will leave the issue up, and fix it when I have time

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