First-order equations: the methods
The validated solver answers "what is y(2)?" with a proof and no formula. A course asks for the formula and for the method that finds it. firstOrder recognises the standard types of equation , carries out the method, and reports every step. exactEquation does the same for .
const s = firstOrder("x - 2*y"); // y' = x - 2y
s.type; // "linear"
s.general; // "y = 1/2*x - 1/4 + C*exp(-2*x)"
s.steps; // [{ what, formula }, …]
const p = s.through(0, 1); // the solution with y(0) = 1
p.solution; // "1/2*x - 1/4 + 5/4*exp(-2*x)"
p.check(1); // { agree: true, numeric: […], formula: […] }
A formula that has been checked
Every closed form here can be compared with the validated numerical solution. check(x1) solves the initial value problem to with proven error bounds and evaluates the formula there with proven error bounds; the two enclosures of must meet. For a solution given only as a relation , the relation is evaluated on the numerical enclosure and must contain the constant. A wrong formula fails this test, so a mistake in the algebra cannot pass unnoticed. A check takes from a fraction of a second to some seconds, depending on the equation.
The types
| type | form | method |
|---|---|---|
| linear | multiply by ; then | |
| separable | ||
| Bernoulli | makes it linear | |
| homogeneous | makes it separable: | |
| exact | with | find with , ; solutions are |
An equation can be of several types: is linear and separable. types lists all that apply and type is the one used; pass { method } to choose. A linear equation is solved as linear because that gives outright. A separable equation gives a relation between and , reported as implicit, and where the relation is easily solved (a logarithm, a reciprocal, an arctangent) also as general.
Dividing by loses the constant solutions with . They are listed in singular.
Why the integrating factor works
For , multiply by . The left side becomes , which is the derivative of the product exactly when , that is . Then is solved by one integration:
Exact equations
If is constant along a solution then . So is solved at once if and for some , and since mixed partials agree that requires . When the test fails, a factor may repair it: if depends on alone then works, and likewise with the roles exchanged. exactEquation tries both.
const e = exactEquation("3*x*y + y^2", "x^2 + x*y");
e.exact; // false
e.factor; // "x"
e.potential; // "y*x^3 + 1/2*y^2*x^2" solutions: that = C
The integrals
The methods need antiderivatives. antiderivative(tree, name) covers polynomials, rational functions by partial fractions, exponentials and sines of linear arguments with polynomial factors, and one level of substitution; it returns nothing unless differentiating its answer gives the integrand back. When an integral is not found, type is null and the validated solver is still there. The fuller engine is in the symbolic package.
| call | returns |
|---|---|
| firstOrder(rhs, { x = "x", y = "y", method }) | { equation, type, types, steps, general, implicit, singular, through } |
| exactEquation(M, N, { x, y }) | the same, with { exact, factor, potential } |
| s.through(x0, y0) | { constant, solution, relation, at(x), check(x1) } |
| antiderivative(tree, name) | { tree, trust: "proven" | "checked" } or null |
@ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.