linear ode calculator

First-Order Linear ODE Solver

Solve initial value problems of the form y’ + p(x)y = q(x) with y(x0) = y0.

Function tips: use * for multiplication and ^ for powers (e.g., x^2).
Supported functions: sin, cos, tan, exp, log, sqrt, abs, asin, acos, atan.
Constants: PI, E.

What this linear ODE calculator does

This calculator is designed for first-order linear differential equations, one of the most important models in engineering, physics, biology, and finance. You enter p(x), q(x), an initial condition, and the point where you want the solution evaluated. The tool then computes an approximate value of y(x) using a high-quality numerical method (RK4).

In plain language: if you have a changing quantity and the rate of change depends linearly on that quantity, this is exactly the type of equation this calculator handles.

Equation form and interpretation

The standard form is:

y’ + p(x)y = q(x)

  • y’ is the derivative of y with respect to x.
  • p(x) scales y and can change with x.
  • q(x) is the forcing/input term.
  • y(x0) = y0 pins down a unique solution.

Many real systems reduce to this form after algebraic rearrangement. If your model starts as y’ = f(x) - g(x)y, it is already linear with p(x)=g(x) and q(x)=f(x).

How the solver works

1) Parse your functions

The calculator converts your typed expressions into JavaScript math expressions. For convenience, it accepts power syntax like x^2.

2) Build the ODE right-hand side

From y’ + p(x)y = q(x), we compute y’ = q(x) - p(x)y.

3) Integrate numerically with RK4

The Runge-Kutta 4th-order method advances the solution from x0 to your target point. It is accurate and stable for a wide range of smooth problems. The calculator also shows sampled points along the path so you can inspect the trend of the solution.

When an exact formula exists

If both p(x) and q(x) are constants, the solution has a closed-form expression:

  • If p ≠ 0: y(x)=q/p + (y0-q/p)e^{-p(x-x0)}
  • If p = 0: y(x)=y0 + q(x-x0)

This page automatically detects that case and reports a closed-form comparison against the numerical result.

Input tips for best results

  • Use explicit multiplication: write 2*x, not 2x.
  • Use radians for trigonometric functions.
  • For logarithms, use log(x) (natural log).
  • Avoid expressions with discontinuities at or near the interval of integration.
  • Check that your initial condition is physically meaningful for your model.

Example use cases

Cooling/heating models

Newton-style thermal models often become linear ODEs with constant or slowly varying coefficients.

RC circuits and first-order systems

Voltage and current dynamics in simple circuits are often modeled by first-order linear equations.

Population and concentration dynamics

Systems with linear decay and external input map directly to this form.

Frequently asked questions

Does this solve second-order ODEs?

No. This calculator is specifically for first-order linear equations of the form shown above.

Is the result exact?

Usually numerical (very accurate for smooth functions), except the constant-coefficient check where a closed form is available.

Why might I see an error?

Typical causes are invalid function syntax, division by zero, or undefined values during integration.

Bottom line

If you need a quick and reliable linear differential equation solver for y’ + p(x)y = q(x) with an initial condition, this calculator gives practical, immediate results and enough diagnostics to trust what you get.

🔗 Related Calculators