First Order Linear ODE Calculator (Integrating Factor)

Put your equation in the standard form y′ + P(x)y = Q(x), type in P and Q and an initial condition, and this calculator carries out the integrating factor method for you: it builds μ(x) = exp(∫P dx), integrates μQ, applies your initial condition, and reports the solution at whatever x you ask for - split into the homogeneous part that remembers y0 and the particular part driven by Q. Both integrals are evaluated numerically, so P and Q need no elementary antiderivative.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
P(x) — the coefficient of yFrom the standard form y' + P(x)y = Q(x). Enter just the coefficient, not the whole term.2
Q(x) — the right-hand sideThe forcing term, after dividing the equation through so that y' has coefficient 1.4
Initial x₀The point where you know the value of y.0
Initial y(x₀)The known value of the solution at x₀.1
Solve at x =Where you want the solution evaluated. It may be on either side of x₀.1

It returns

  • y at the target x — The particular solution through your initial condition, evaluated at the target.
  • Integrating factor μ(x) — Normalised so that μ(x₀) = 1.
  • Homogeneous part y₀/μ
  • Particular part (∫μQ)/μ
  • ∫ μ(t)Q(t) dt from x₀
  • Slope y′ at the target — Computed straight from the equation as Q(x) − P(x)y(x).

The formula

y(x)=μ(x)Q(x)dx+Cμ(x),μ(x)=eP(x)dx
dydx+P(x)y=Q(x)

In plain text: μ(x) = e^∫P dx ; y(x) = [∫ μ(x)Q(x) dx + C] / μ(x)

  • y(x)The unknown function you are solving for
  • P(x)The coefficient of y in standard form
  • Q(x)The forcing term on the right-hand side
  • μ(x)Integrating factor, exp(∫P dx); normalised here so μ(x₀) = 1
  • CConstant of integration, fixed by the initial condition y(x₀) = y₀

Valid only for equations already in the standard form y′ + P(x)y = Q(x). Divide through by the coefficient of y′ first.

Updated Category Differential Equations Verified against published test cases Reading time 11 min

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.

  1. Identify the pieces. P(x) = 2, Q(x) = 4, x0 = 0, y0 = 1.
  2. Integrating factor. ∫P dx = 2x, so μ(x) = e2x. At x = 1 that is e2 = 7.3890561.
  3. Multiply through. e2xy′ + 2e2xy = 4e2x, and the left side is exactly (e2xy)′.
  4. Integrate the right side from 0 to 1. ∫4e2tdt = 2e2t, evaluated from 0 to 1 gives 2(7.3890561 − 1) = 12.7781122.
  5. 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

Common first-order linear equations, already in standard form.
EquationP(x)μ(x)General solutionWhere it turns up
y′ + py = qpepxq/p + Ce−pxNewton cooling, RC charging, mixing tanks
y′ + py = q ekxpepxq ekx/(p+k) + Ce−px, for k ≠ −pExponentially ramped forcing
y′ − py = q epx−pe−px(qx + C)epxResonant forcing - note the factor of x
y′ + (a/x)y = qa/xxaqx/(a+1) + Cx−a, for a ≠ −1Radial problems, Euler equations
y′ + y tan x = qtan xsec xq sin x + C cos xTrigonometric coefficient problems
y′ = q(x)01∫q dx + CPure 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 not P = 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 substitution v = 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, namely C/μ(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.

Frequently asked questions

How do I know my equation is first-order linear?

Rearrange it so that dy/dx is alone on the left with coefficient 1. If what remains is a function of x multiplying y, plus a function of x on its own, it is linear. Any appearance of y², 1/y, sin y, e^y or y·y′ disqualifies it. Note that P and Q can be arbitrarily nasty in x - y′ + x²sin(x)y = ln x is perfectly linear.

Why is the integrating factor an exponential?

Because you need μ′ = Pμ for the product rule to run backwards, and the exponential is the function whose derivative is proportional to itself. Solve that little equation by separation - dμ/μ = P dx, so ln μ = ∫P dx - and exponentiate. It is the only choice up to a constant multiple, and the multiple cancels.

Does the constant of integration in ∫P dx matter?

No. Adding a constant k to ∫P dx multiplies μ by e^k, and μ appears in both the numerator and the denominator of the final expression, so the factor cancels exactly. This calculator normalises μ(x₀) = 1 for that reason, which makes the reported number easy to interpret: it is the factor by which the initial condition has been damped or amplified.

What if I cannot integrate μQ in closed form?

You compute it numerically, which is exactly what this calculator does. Plenty of perfectly ordinary problems have no elementary antiderivative - y′ + y = e−x² is one - and the integrating factor method still gives the right answer, just as a number rather than a formula. The structure of the solution, homogeneous plus particular, is unchanged.

Can I solve without an initial condition?

The general solution is y = [∫μQ dx + C]/μ with C arbitrary, so it is a family of curves rather than a single one. This calculator asks for an initial condition because it returns numbers, and a number needs a specific curve. Enter the condition you have; if you genuinely want the general solution, vary y₀ and watch the whole family sweep out in the chart.

What does it mean when the answer barely depends on the initial value?

It means the integrating factor at your target is large, so the term y₀/μ has been damped almost to nothing. Physically, the system has run for many time constants and has forgotten where it started; the answer is set by the forcing Q alone. The opposite case - a μ much smaller than 1 - means the initial condition is being amplified, and any uncertainty in y₀ is amplified with it.

How accurate is the numerical answer?

Both integrals are evaluated with fourth-order composite Simpson-type steps on 400 subintervals, so the error falls as the fourth power of the step size and is typically below one part in 10¹⁰ for smooth P and Q. Accuracy degrades where P or Q varies violently within a step, or near a singularity, which is when the warning about non-finite values appears.

What is the difference between this and separation of variables?

Separation needs the equation to factor as y′ = f(x)g(y), which a linear equation does only when Q is zero. The integrating factor works for any Q. If your equation is both - the homogeneous case - either method works and gives the same answer. For genuinely nonlinear problems that separate, separation is the tool; there is no integrating factor of this kind for them.

References

  • Elementary Differential Equations and Boundary Value Problems, 11th ed. (Section 2.1, Linear Equations; Method of Integrating Factors) — William E. Boyce, Richard C. DiPrima and Douglas B. Meade, Wiley
  • Differential Equations with Applications and Historical Notes, 3rd ed. — George F. Simmons, CRC Press
  • Numerical Analysis, 10th ed. (Chapter 4, Numerical Differentiation and Integration) — Richard L. Burden and J. Douglas Faires, Cengage Learning