Course Test · University: first two years
Ordinary differential equations: RatMath answers
The same twenty exercises, answered with RatMath Core and the Shelf libraries only. The code below was run when this page was built; its output is shown as printed, and compared with the independent answer.
Agrees 20
Libraries used here: core, analytic, symbolic. In this code each library is in scope under its own name (linalg.det, stats.tTest), and Core's names (R, Rational, …) are in scope directly.
- 1.SeparableAgreesSolve , .Independent answer, : .RatMath code
analytic.firstOrder("x*y^2").through(0, 1).solutionOutput-(2/(x^2 - 2))
- 2.Linear, integrating factorAgreesSolve , .Independent answer: .RatMath code
analytic.firstOrder("exp(-x) - 2*y").through(0, 0).solutionOutputexp(-x) - exp(-2*x)
- 3.Exact equationAgreesSolve .Independent answer. .RatMath code
analytic.exactEquation("2*x*y + 3", "x^2 - 1").implicitOutputy*x^2 + 3*x - y = C
- 4.BernoulliAgreesSolve .Independent answer: , : (and ).RatMath code
analytic.firstOrder("y^2 - y").generalOutputy = 1/(C*exp(x) + 1)
- 5.HomogeneousAgreesSolve for .Independent answer: , : .RatMath code
analytic.firstOrder("(x + y)/x").generalOutputy = log(abs(x))*x + C*x
firstOrderrecognises the equation as linear (and it is also homogeneous) but returns no solution.Fix: ratmath/analytic#18, exact starting values,pointwiselimits,sec/csc/cot, integrating factors with ,ODESolutionexported - 6.Distinct real rootsAgreesSolve .Independent answer, : .RatMath code
analytic.linearODE([1, -5, 6]).generalOutputy = C1*exp(2*x) + C2*exp(3*x)
- 7.Repeated rootAgreesSolve , , .Independent answer; , : .RatMath code
analytic.linearODE([1, 4, 4]).initial([1, 0]).solutionOutputy = 2*x*exp(-2*x) + exp(-2*x)
- 8.Complex rootsAgreesSolve .Independent answer: .RatMath code
analytic.linearODE([1, 2, 5]).generalOutputy = C1*cos(2*x)*exp(-x) + C2*sin(2*x)*exp(-x)
- 9.Undetermined coefficientsAgreesFind a particular solution of .Independent answer: , : .RatMath code
analytic.linearODE([1, -3, 2], "4*x").particularOutput2*x + 3
- 10.ResonanceAgreesFind a particular solution of .Independent answer.RatMath code
analytic.linearODE([1, 0, 1], "cos(x)").particularOutput1/2*x*sin(x)
- 11.Variation of parametersAgreesFind a particular solution of .Independent answer.RatMath code
analytic.linearODE([1, 0, 1], "sec(x)").particularOutputlog(abs(cos(x)))*cos(x) + x*sin(x)
Bug:sec(x)was read as the product of a variable sec and , so the answer came back assec*x. Written as1/cos(x)it was solved correctly.Fix: ratmath/analytic#18, exact starting values,pointwiselimits,sec/csc/cot, integrating factors with ,ODESolutionexported - 12.Laplace transformAgreesFind .Independent answer.RatMath code
analytic.laplace("t^2*exp(3*t)")Output2/(s - 3)^3
- 13.Inverse Laplace transformAgreesFind .Independent answer: .RatMath code
analytic.inverseLaplace("(s + 1)/(s^2 + 4*s + 13)").resultOutputcos(3*t)*exp(-2*t) + -1/3*sin(3*t)*exp(-2*t)
- 14.Step forcingAgreesSolve , , where is the unit step.Independent answer: .RatMath code
analytic.laplaceSolve([1, 1], "heaviside(t - 1)", [0]).solutionOutputheaviside(t - 1)*(1 - exp(-t + 1))
- 15.Linear systemAgreesSolve and classify the origin.Independent answerEigenvalues 3 with , with : . A saddle, unstable.RatMath code
const L = analytic.linearSystem([[1, 2], [2, 1]]); [L.eigenvalues, L.eigenvectors, L.kind, L.stability]Output[["-1", "3"], [["2", "-2"], ["2", "2"]], "saddle", "unstable"]
- 16.Classifying an equilibriumAgreesClassify the origin for , .Independent answerTrace , determinant 1, discriminant : a stable spiral.RatMath code
const L = analytic.linearSystem([[0, 1], [-1, -1]]); [L.kind, L.stability]Output["stable spiral", "asymptotically stable"]
- 17.Nonlinear phase planeAgreesFind and classify the equilibria of , with .Independent answersaddle; saddle; : Jacobian , trace , det 2: stable spiral.RatMath code
const mid = (iv) => Math.round(iv.low.add(iv.high).toNumber() / 2); analytic.planarSystem(["x*(3 - x - y)", "y*(x - 1)"]).equilibria({ x: ["-1", "4"], y: ["-1", "3"] }).map((e) => [e.point.map(mid), e.kind])Output[[[0, 0], "saddle"], [[1, 2], "stable spiral"], [[3, 0], "saddle"]]
- 18.Series solutionAgreesFind the first terms of the power series solutions of Airy's equation about 0.Independent answer: and .RatMath code
analytic.seriesSolution({ p: 0, q: "-x", order: 7 }).solutions.map((s) => s.text)Output["1 + 1/6*x^3 + 1/180*x^6 + …", "x + 1/12*x^4 + 1/504*x^7 + …"]
- 19.Euler's methodAgreesUse Euler's method with on , to estimate .Independent answer: (true value ).RatMath code
analytic.odeMethod("y", { method: "euler", y0: 1, until: 1, steps: 4 }).steps.at(-1).yOutput2.44140625
- 20.Newton's law of coolingAgreesCoffee at 90° cools in a 20° room, . After 10 minutes it is 60°. What is it after 20 minutes?Independent answer, . At 20 minutes: .RatMath code
PRINT(analytic.firstOrder("-k*(T - 20)", { y: "T", x: "t" }).general); // T = 20 + C e^(−kt), and C = 70 from T(0) = 90 const k = symbolic.solve("70*exp(-10*k) = 40", "k").solutions[0].value; PRINT("k =", k); String(symbolic.simplify(`20 + 70*exp(-20*(${k}))`))Output300/7
The general solution comes fromfirstOrder, from the data bysolve, and is simplified exactly to . Reading off from is done by hand.