grid.ode module#
Linear ordinary differential equation solver.
Solves a linear ordinary differential equation of order \(K\) of the form
with either boundary conditions on the two end-points for some unknown function \(y(x)\) with independent variable \(x\) or as an initial value problem on a interval.
It also supports the ability to transform the independent variable \(x\) to another domain \(g(x)\) for some \(K\)-th differentiable transformation \(g(x)\). This is particularly useful to convert infinite domains, e.g. \([0, \infty)\), to a finite interval.
- grid.ode.solve_ode_bvp(x: ndarray, fx: callable, coeffs: list | ndarray, bd_cond: list, transform: BaseTransform = None, tol: float = 0.0001, max_nodes: int = 5000, initial_guess_y: ndarray = None, no_derivatives: bool = True)#
Solve a linear ODE with boundary conditions.
Parameters#
- xnp.ndarray(N,)
Points of the independent variable/domain. If transform is provided, then these are the points that are to be transformed.
- fxcallable
Right-hand function \(f(x)\).
- coeffslist[callable or float] or ndarray(K + 1,)
Coefficients \(a_k\) of each term \(\frac{d^k y(x)}{d x^k}\) ordered from 0 to K. Either a list of callable functions \(a_k(x)\) that depends on \(x\) or array of constants \(\{a_k\}_{k=0}^{K}\).
- bd_condlist[list[int, int, float]]
Boundary condition specified by list of size \(K\) of three entries [i, j, C], where \(i \in \{0, 1\}\) determines whether the lower or upper bound is being constrained, \(j \in \{0, \cdots, K\}\) determines which derivative \(\frac{d^j y}{dx^j}\) is being constrained, and \(C\) determines the boundary constraint value, i.e. \(\frac{d^j y}{dx^j} = C\). Size needs to be the same as the order \(K\) of the ODE. If transform is given, then the constraint of the derivatives is assumed to be with respect to the new coordinate i.e. \(\frac{d^j y}{dr^j} = C\).
- transformBaseTransform, optional
Transformation from one domain \(x\) to another \(r := g(x)\).
- tolfloat, optional
Tolerance of the ODE solver and for the boundary condition residuals. See scipy.integrate.solve_bvp for more info.
- max_nodesint, optional
The maximum number of mesh nodes that determine termination. See scipy.integrate.solve_bvp function for more info.
- initial_guess_yndarray(K, N), optional
Initial guess for \(y(x), \cdots, \frac{d^{K} y}{d x^{K}}\) at the points x. If not provided, then random set of points from 0 to 1.
- no_derivativesbool, optional
If true, when transform is used then it only returns the solution \(y(x)\) rather than its derivative. If false, it includes the derivatives up to \(P-1\).
Returns#
- callable :
Interpolate function (scipy.interpolate.PPoly) instance whose input is the original domain \(x\) and output is an array of the function \(y(x)\) evaluated on the points and its derivatives wrt to \(x\) up to \(K - 1\).
- grid.ode.solve_ode_ivp(x_span: tuple, fx: callable, coeffs: list | ndarray, y0: list | ndarray, transform: BaseTransform = None, method: str = 'DOP853', no_derivatives: bool = False, rtol: float = 1e-08, atol: float = 1e-06)#
Solve a linear ODE as an initial value problem.
Parameters#
- x_span(int, int)
The interval of integration \((t_0, t_1)\) from the first point to the second point.
- fxcallable
Right-hand function \(f(x)\).
- coeffslist[callable or float] or ndarray(K + 1,)
Coefficients \(a_k\) of each term \(\frac{d^k y(x)}{d x^k}\) ordered from 0 to K. Either a list of callable functions \(a_k(x)\) that depends on \(x\) or array of constants \(\{a_k\}_{k=0}^{K}\).
- y0list[K] or ndarray(K)
The initial value conditions \(\frac{d^k y(t_0)}{d x^k} = c_k\) at the initial point \(t_0\) from \(k=0,\cdots,K-1\).
- transformBaseTransform, optional
Transformation from one domain \(x\) to another \(r := g(x)\).
- methodstr
The method used to solve the ode by scipy. See scipy.integrate.solve_ivp function for more info.
- no_derivativesbool, optional
If true, when transform is used then it only returns the solution \(y(x)\) rather than its derivative. If false, it includes the derivatives up to \(P-1\).
- rtol, atol(float, float), optional
The relative and absolute tolerance. See scipy.integrate.solve_ivp for more info.
Returns#
- callable :
Interpolate function (scipy.interpolate.PPoly) instance whose input is the original domain \(x\) and output is an array of the function \(y(x)\) evaluated on the points and its derivatives wrt to \(x\) up to \(K - 1\).