What a first-order linear ODE looks like, and why the integrating factor works
A first-order linear differential equation is any equation you can write in the standard form
dy/dx + P(x) y = Q(x)
Linear here means linear in y and its derivative: no y2, no sin y, no y dy/dx. The coefficients P and Q may be as complicated as you like in x. Get your equation into that shape first - divide through by whatever multiplies dy/dx - because every step that follows assumes it.
The trick is to multiply the whole equation by a carefully chosen function μ(x) so that the left-hand side collapses into a single derivative. Multiply through and you want
μ y′ + μP y = (μy)′ = μy′ + μ′y
Comparing the two middle terms, that works precisely when μ′ = Pμ, whose solution is μ(x) = exp(∫P dx). There is nothing mysterious about the choice: it is the only function that makes the product rule run backwards.
Once the left side is (μy)′, integrate both sides and the problem is finished:
μ(x) y(x) = ∫μ(x)Q(x) dx + C, so y = [∫μQ dx + C] / μ
This calculator evaluates both integrals numerically, to fourth-order accuracy, which means it works for any P and Q you can type - including combinations that have no elementary antiderivative at all, like Q(x) = exp(-x^2). The method is the same; only the last step is arithmetic instead of algebra.
Reading the solution as two pieces
Write the solution with the integrals taken from the initial point x0 and it splits cleanly:
y(x) = y₀/μ(x) + [∫ from x₀ to x of μ(t)Q(t) dt] / μ(x)
with μ(x) = exp(∫ from x₀ to x of P(t) dt), so that μ(x₀) = 1. The calculator reports both pieces separately.
The first piece is the homogeneous part - the solution of y′ + Py = 0, which is what you would get with no forcing at all. It carries the entire memory of the initial condition and nothing else. If P is a positive constant p, this term is y₀e−px, and it decays; if p is negative it grows. That single sign decides whether the system forgets its starting point or is dominated by it.
The second piece is the particular part - the response to the forcing Q, with zero initial value. It knows nothing about y0. In an electrical or thermal context this is the driven response, and the homogeneous term is the transient that fades.
Because the equation is linear, these two add. Doubling y0 doubles the first term and leaves the second alone; doubling Q does the reverse. That superposition is what linear buys you, and it is exactly what fails for a nonlinear equation.
Note that any constant multiple of μ gives the same answer, because it appears in both the numerator and the denominator. That is why textbooks drop the constant of integration when computing ∫P dx, and why this calculator normalises μ(x₀) = 1.
Worked example: y′ + 2y = 4 with y(0) = 1
This is the standard Newton-cooling shape: a quantity relaxing towards a steady value.
- Identify the pieces. P(x) = 2, Q(x) = 4, x0 = 0, y0 = 1.
- Integrating factor. ∫P dx = 2x, so μ(x) = e2x. At x = 1 that is e2 = 7.3890561.
- Multiply through. e2xy′ + 2e2xy = 4e2x, and the left side is exactly (e2xy)′.
- Integrate the right side from 0 to 1. ∫4e2tdt = 2e2t, evaluated from 0 to 1 gives 2(7.3890561 − 1) = 12.7781122.
- Divide by μ. y(1) = (1 + 12.7781122) / 7.3890561 = 13.7781122 / 7.3890561 = 1.8646647.
Check it algebraically. The general solution is y = 2 + Ce−2x; the initial condition gives 1 = 2 + C, so C = −1 and y = 2 − e−2x. At x = 1, e−2 = 0.1353353, so y(1) = 2 − 0.1353353 = 1.8646647. The two agree.
The split the calculator reports is visible in that closed form. The homogeneous part is y₀/μ = 1/7.3890561 = 0.1353353, and the particular part is 12.7781122/7.3890561 = 1.7293294. They sum to 1.8646647. As x grows the first term vanishes and the second approaches Q/P = 4/2 = 2, the steady state - which is the horizontal asymptote in the chart.
A second case worth working by hand, because it is the one students most often get wrong: y′ + y/x = x with y(1) = 1. Here ∫P dx = ln x so μ = x, the equation becomes (xy)′ = x², and integrating from 1 to 2 gives xy = x³/3 + C. From the initial condition, 1 = 1/3 + C, so C = 2/3, and at x = 2, y = (8/3 + 2/3)/2 = (10/3)/2 = 5/3 = 1.6666667.
How to read the answer
Start with the sign of P. Over any interval where P is positive, the integrating factor grows and the homogeneous term y₀/μ shrinks, so the solution loses memory of where it started and settles towards whatever the forcing dictates. Over any interval where P is negative, the reverse happens: the initial condition is amplified and small errors in y0 grow with it. The calculator prints μ at the target, and that single number tells you which regime you are in.
For constant P = p > 0 and constant Q = q, the solution approaches the steady value q/p with time constant 1/p. After one time constant the gap to the steady value has shrunk to e−1 = 36.8% of its starting size; after three, to 5.0%; after five, to 0.67%. That is the same arithmetic as an RC circuit charging, a tank mixing, or a body cooling, because all three are the same equation.
The slope output is y′ = Q − Py evaluated at the target, straight from the differential equation rather than from any numerical difference. It is a useful sanity check: at a steady state it should be essentially zero, and its sign tells you whether the solution is still rising or falling at that point.
Watch for a very large or very small integrating factor. When μ reaches 1012 or so, the answer is being computed as a ratio of huge numbers and precision suffers; the calculator warns you when that happens. It is usually a sign that the target is many time constants away from the initial point, in which case the homogeneous term is numerically zero and the answer is just the steady response.
Standard forms and their integrating factors
| Equation | P(x) | μ(x) | General solution | Where it turns up |
|---|---|---|---|---|
| y′ + py = q | p | epx | q/p + Ce−px | Newton cooling, RC charging, mixing tanks |
| y′ + py = q ekx | p | epx | q ekx/(p+k) + Ce−px, for k ≠ −p | Exponentially ramped forcing |
| y′ − py = q epx | −p | e−px | (qx + C)epx | Resonant forcing - note the factor of x |
| y′ + (a/x)y = q | a/x | xa | qx/(a+1) + Cx−a, for a ≠ −1 | Radial problems, Euler equations |
| y′ + y tan x = q | tan x | sec x | q sin x + C cos x | Trigonometric coefficient problems |
| y′ = q(x) | 0 | 1 | ∫q dx + C | Pure quadrature - the degenerate case |
Every row follows from μ = exp(∫P dx) and y = [∫μQ dx + C]/μ. The third row shows what happens when the forcing matches the homogeneous solution: the particular solution picks up a factor of x.
Mistakes that produce a wrong solution
- Not putting the equation in standard form first.
x y′ + 2y = x³is notP = 2. Divide by x first:y′ + (2/x)y = x², so P = 2/x and μ = x². - Forgetting to multiply the right-hand side by μ. The most common slip in hand work. Both sides get multiplied, always.
- Applying the initial condition before integrating. The constant C belongs to the integrated equation
μy = ∫μQ dx + C, not to the differential one. - Using the method on a nonlinear equation. If y appears squared, inside a function, or multiplying its own derivative, there is no integrating factor of this form. A Bernoulli equation
y′ + Py = Qyⁿbecomes linear after the substitutionv = y1−n; a separable equation should just be separated. - Integrating across a singularity of P. For
P = 1/x, the solution through x = 1 says nothing about x = −1: the interval of validity stops at the singularity. The calculator warns when the integration runs into one. - Dropping the absolute value in ∫dx/x = ln|x|. It matters for negative x, though the sign cancels between μ in the numerator and denominator, which is why textbooks get away with ignoring it.
Where this method sits
The integrating factor is the complete theory for first-order linear equations - there is nothing else to learn about them. Every other first-order technique is for a different class: separation of variables handles y′ = f(x)g(y), exact equations handle M dx + N dy = 0 with ∂M/∂y = ∂N/∂x, and substitutions reduce homogeneous or Bernoulli equations to one of those. An equation can belong to more than one class; y′ + 2y = 0 is both linear and separable, and either route gives y = Ce−2x.
Move up one order and the analogue is the Laplace transform or the characteristic-equation method, which turn a constant-coefficient linear ODE into algebra. The split into homogeneous plus particular survives unchanged at every order; only the machinery for finding each piece gets heavier.
When the equation is not linear, or when P and Q come from data rather than from a formula, you integrate numerically instead. The Euler method is the simplest such scheme and the fourth-order Runge-Kutta method is the standard workhorse; both handle y′ = f(x, y) with no structure assumed at all. It is worth solving a linear problem both ways once: the numerical solution should track the exact one to within the scheme's error, and if it does not, the bug is usually in the standard form rather than in the integrator.
Underneath the integrals themselves are the quadrature rules - this calculator uses composite Simpson-type steps, the same rule you get by integrating a quadratic interpolating polynomial, and documented in the Simpson's rule calculator. If you want the antiderivatives in closed form rather than numerically, the indefinite integral calculator is the right tool.
Key terms
- Standard form
dy/dx + P(x)y = Q(x). Everything in the method assumes the coefficient of dy/dx is exactly 1.- Integrating factor
μ(x) = exp(∫P dx). The multiplier that turns the left-hand side into the derivative of a single product.- Homogeneous solution
- The solution of
y′ + Py = 0, namelyC/μ(x). It carries the initial condition. - Particular solution
- Any single solution of the full equation. Here, the one with zero value at x₀, driven entirely by Q.
- Initial value problem
- The differential equation together with a condition y(x₀) = y₀, which pins down C and makes the solution unique.
