Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solving integro-differential coupled system of equations with Python

Tags:

python

scipy

I'm trying to use Python to numerically solve a system of equations described in this paper, Eqs. 30 and 31, with a simplified form looking like:

enter image description here

where G(k) and D(k) are some known functions, independent of Y. Of course, all quantities are functions of t as well. The authors comment that, due to the dependence exhibited by the various functions, a numerical solution is necessary.

I usually implement the solution to this type of coupled equations as indicated here or here, for example, but now the extra k-dependence is confusing me a bit.

Any suggestions? Thanks a lot.

like image 769
surrutiaquir Avatar asked Jul 11 '26 19:07

surrutiaquir


1 Answers

IDESolver is a general-purpose numerical integro-differential equation solver created by Josh Karpel. Its latest version allows the user to solve multidimensional, coupled IDEs. From the examples provided, an IDE like

enter image description here

with analytical solution (sin x, cos x), can be solved using the following piece of code:

import numpy as np
import matplotlib.pyplot as plt
from idesolver import IDESolver

solver = IDESolver(
            x=np.linspace(0, 7, 100),
            y_0=[0, 1],
            c=lambda x, y: [0.5 * (y[1] + 1), -0.5 * y[0]],
            d=lambda x: -0.5,
            f=lambda y: y,
            lower_bound=lambda x: 0,
            upper_bound=lambda x: x,
)

solver.solve()

fig = plt.figure(dpi = 600)
ax = fig.add_subplot(111)

exact = [np.sin(solver.x), np.cos(solver.x)]

ax.plot(solver.x, solver.y[1], label = 'IDESolver Solution', linestyle = '-', linewidth = 3)
ax.plot(solver.x, exact[1], label = 'Analytic Solution', linestyle = ':', linewidth = 3)

ax.legend(loc = 'best')
ax.grid(True)

ax.set_title(f'Solution for Global Error Tolerance = {solver.global_error_tolerance}')
ax.set_xlabel(r'$x$')
ax.set_ylabel(r'$y(x)$')

plt.show()
like image 165
surrutiaquir Avatar answered Jul 14 '26 07:07

surrutiaquir