Cadabra
a field-theory motivated approach to computer algebra

cdb.numeric.integrate

Functions for numeric integration and numeric solutions to differential equations
A collection of wrappers for some of the numeric functionality of the scipy library in order to accept cadabra Ex objects
import numpy from scipy.integrate import odeint from cdb.numeric.evaluate import lambdify, _create_sublist

integrate_ode(eqns: Ex|Iterable[Ex], variables: Ex|Iterable[Ex], initial_values: List[float], endpoint: float, delta: float, constants: Ex|dict) -> List

Numerically integrate a system of ODEs over a range of values
\begin{description} \item eqns \\ List of expressions representing first order derivatives with respect to a common variable. The expression should not contain the derivative, so e.g. use $x - \frac{1}{2}xy$ instead of $\partial_{t}{x} = x - \frac{1}{2}xy$. Can be a comma-separated in an Ex object, or any iterable of Ex objects. \item variables \\ List of variables, starting with the derivative variable and then each variable in the order that its derivative appears in eqns, so $(\frac{dx}{dt}, \frac{dy}{dt}, \frac{dz}{dt})$ would have variables $(t, x, y, z)$ \item initial_values \\ The initial values of each variable in variables as a floating point number \item endpoint \\ The value of the derivative variable at which to finish \item delta \\ The amount to increase the derivative variable at each iteration \item constants \\ Ex or dictionary object with a list of substitutions of constants to be performed before the numeric integration \end{description}
{t}::Coordinate. dx := x-A*x*y. dy := -B*y + C*x*y. #sols = integrate_ode((dx, dy), $t, x, y$, (0, 1, 1), 10, 0.001, $A->1/2, B->3/4, C->1/4$) sols = integrate_ode($@(dx), @(dy)$, $t, x, y$, (0, 1, 1), 10, 0.001, {"A": 0.5, "B": 3/4, "C": 0.25})
import matplotlib.pyplot as plt fig, axes = plt.subplots(2,1) axes[0].plot(sols[0], sols[1]) axes[0].plot(sols[0], sols[2]) axes[1].plot(sols[1], sols[2]) fig;
Raux::LaTeXForm("R_{aux}") laux::LaTeXForm("\lambda_{aux}") dR := Raux; dRaux := -(4* M**2* Raux + 2* r**2* Raux + 2*( laux * R - 3* r * Raux ) * M + ( \omega**2* r**3 - laux * r ) * R ) /(4* M**2* r - 4* M * r**2 + r**3); sols = integrate_ode((dR, dRaux), $r, R, Raux$, (0.3, 1, 0.5), 100, 0.01, $M->0.1, \omega->0.2, k->2, laux->2$)
\(\displaystyle{}R_{aux}\)
Raux
\(\displaystyle{}-\left(4{M}^{2} R_{aux}+2{r}^{2} R_{aux}+2\left(\lambda_{aux} R-3r R_{aux}\right) M+\left({\omega}^{2} {r}^{3}-\lambda_{aux} r\right) R\right) {\left(4{M}^{2} r-4M {r}^{2}+{r}^{3}\right)}^{-1}\)
-(4(M)**2 Raux + 2(r)**2 Raux + 2(laux R-3r Raux) M + ((\omega)**2 (r)**3-laux r) R) (4(M)**2 r-4M (r)**2 + (r)**3)**(-1)
fig, axes = plt.subplots(2,1) axes[0].plot(sols[0], sols[1]) fig;
Copyright © 2001-2024 Kasper Peeters
Questions? info@cadabra.science