Skip to content

Differential Equation Solver with Steps

Solve first- and second-order ODEs with initial conditions, steps, graph and RK4 numerics.

Your details

Results update as you type

Solution

y = 2 − 2e^(−2x)

Value of y at the chosen point
1.729329
Slope y′ at that point
0.541341
General solution
y = 2 + Ce^(−2x)
Equilibrium y = b/a
2

Step-by-step solution
  1. Standard form: y′ + 2y = 4
  2. Integrating factor: μ = e^(∫a dx) = e^(2x)
  3. General solution: (μy)′ = bμ ⇒ y = 2 + Ce^(−2x)
  4. Initial condition: y(0) = 0 ⇒ C = y₀ − b/a = −2
  5. Particular solution: y = 2 − 2e^(−2x)
  6. Equilibrium y = 2: stable, every solution tends to it.
  7. Value: y(1) = 1.72933

Solution values

A differential equation links an unknown function yy to its derivatives: y′=−0.1yy' = -0.1y says that a quantity loses 10 % of itself per unit of time, y′′+4y=0y'' + 4y = 0 describes a spring that oscillates forever. Solving it means finding every function that satisfies the relation, and then the one function that also matches the starting data, the initial conditions.

This differential equation solver covers the ordinary differential equations (ODEs) met in a first course, each with its exact closed-form answer and the working:

  • First-order linear with constant coefficients, y′+ay=by' + ay = b, solved with an integrating factor.
  • Exponential growth or decay, y′=ryy' = ry, and the logistic model y′=ry(1−y/K)y' = ry(1 - y/K), with doubling time, half-life or inflection time.
  • Second-order linear with constant coefficients, ay′′+by′+cy=day'' + by' + cy = d: characteristic equation, the three root cases and the constants fitted to y(x0)y(x_0) and y′(x0)y'(x_0).
  • Any first-order equation y′=f(x,y)y' = f(x, y), solved numerically with the fourth-order Runge–Kutta method (RK4) and compared with Euler’s method.

Every result comes with a graph of yy over the interval and a table of values, so you can see the shape of the solution, not only one number.

How to use this calculator

  1. Choose the equation type.
  2. Enter the coefficients. For y′+ay=by' + ay = b type aa and bb; for the second-order equation type aa, bb, cc and the constant dd (leave d=0d = 0 for a homogeneous equation).
  3. Enter the initial conditions: the starting point x0x_0 and y(x0)y(x_0), plus y′(x0)y'(x_0) for a second-order equation. The growth models start at t=0t = 0.
  4. Enter the point where you want the value, xx or tt. The chart and the table run from the start to that point.
  5. For the numerical mode, type the right-hand side f(x,y)f(x, y) — for example x + y or sin(x) - y — and the number of steps nn. More steps give a smaller error.
  6. Open the steps to follow the method line by line.

The formula

First-order linear. Multiply y′+ay=by' + ay = b by the integrating factor eaxe^{ax}: the left side becomes (eaxy)′(e^{ax}y)', and integrating gives

y=ba+(y0−ba)e−a(x−x0)(a≠0),y=y0+b(x−x0)(a=0).y = \frac{b}{a} + \Big(y_0 - \frac{b}{a}\Big)e^{-a(x - x_0)} \quad (a \neq 0), \qquad y = y_0 + b(x - x_0) \quad (a = 0).

Growth models. Separating variables in y′=ryy' = ry gives y=y0erty = y_0e^{rt}, with doubling time (or half-life) ln⁡2/∣r∣\ln 2/|r|. The logistic equation gives

y=K1+Ce−rt,C=K−y0y0,y = \frac{K}{1 + Ce^{-rt}}, \qquad C = \frac{K - y_0}{y_0},

and the curve is steepest when y=K/2y = K/2, at t=ln⁡(C)/rt = \ln(C)/r.

Second order. Substituting y=erxy = e^{rx} into ay′′+by′+cy=0ay'' + by' + cy = 0 gives the characteristic equation ar2+br+c=0ar^2 + br + c = 0:

Discriminant Roots General solution
b2−4ac>0b^2 - 4ac > 0 r1≠r2r_1 \neq r_2 real C1er1x+C2er2xC_1e^{r_1x} + C_2e^{r_2x}
b2−4ac=0b^2 - 4ac = 0 rr repeated (C1+C2x)erx(C_1 + C_2x)e^{rx}
b2−4ac<0b^2 - 4ac < 0 α±βi\alpha \pm \beta i eαx(C1cos⁡βx+C2sin⁡βx)e^{\alpha x}(C_1\cos\beta x + C_2\sin\beta x)

A constant right-hand side dd adds the particular solution d/cd/c (or dx/bdx/b if c=0c = 0, dx2/(2a)dx^2/(2a) if b=c=0b = c = 0). C1C_1 and C2C_2 then follow from y(x0)y(x_0) and y′(x0)y'(x_0).

RK4. With step h=(x1−x0)/nh = (x_1 - x_0)/n:

yn+1=yn+h6(k1+2k2+2k3+k4),y_{n+1} = y_n + \frac{h}{6}(k_1 + 2k_2 + 2k_3 + k_4),

where k1=f(xn,yn)k_1 = f(x_n, y_n), k2=f(xn+h2,yn+h2k1)k_2 = f(x_n + \tfrac h2, y_n + \tfrac h2k_1), k3=f(xn+h2,yn+h2k2)k_3 = f(x_n + \tfrac h2, y_n + \tfrac h2k_2) and k4=f(xn+h,yn+hk3)k_4 = f(x_n + h, y_n + hk_3). Its global error shrinks like h4h^4; Euler’s yn+1=yn+hf(xn,yn)y_{n+1} = y_n + hf(x_n, y_n) only like hh.

Worked example

First order (the default). For y′+2y=4y' + 2y = 4 with y(0)=0y(0) = 0: b/a=2b/a = 2 and C=0−2=−2C = 0 - 2 = -2, so y=2−2e−2xy = 2 - 2e^{-2x}. At x=1x = 1 the solver gives y(1)=1.729329y(1) = 1.729329 and a slope of 0.541341; every solution approaches the stable equilibrium y=2y = 2.

Distinct roots. y′′−3y′+2y=0y'' - 3y' + 2y = 0, y(0)=0y(0) = 0, y′(0)=1y'(0) = 1: r2−3r+2=0r^2 - 3r + 2 = 0 has roots 2 and 1, the conditions give C1=1C_1 = 1, C2=−1C_2 = -1, so y=e2x−exy = e^{2x} - e^{x} and y(1)=4.670774y(1) = 4.670774.

Complex roots. y′′+4y=0y'' + 4y = 0, y(0)=1y(0) = 1, y′(0)=0y'(0) = 0: roots ±2i\pm 2i, so y=cos⁡2xy = \cos 2x and y(1)=−0.416147y(1) = -0.416147.

Repeated root. y′′+2y′+y=0y'' + 2y' + y = 0, y(0)=1y(0) = 1, y′(0)=0y'(0) = 0: r=−1r = -1 twice, so y=(1+x)e−xy = (1 + x)e^{-x} and y(1)=0.735759y(1) = 0.735759.

Logistic. K=100K = 100, y(0)=10y(0) = 10, r=0.5r = 0.5: C=9C = 9, y=100/(1+9e−0.5t)y = 100/(1 + 9e^{-0.5t}), inflection at t=ln⁡9/0.5=4.394449t = \ln 9/0.5 = 4.394449, and y(10)=94.282562y(10) = 94.282562.

RK4. y′=yy' = y, y(0)=1y(0) = 1 from 0 to 1 in 100 steps gives 2.71828183 — ee to eight decimals — while Euler gives 2.70481383.

A diff eq solver with steps, not just an answer

“Diff eq” is the usual student shorthand for differential equations, and most searches for a diff eq solver or a diff equation calculator come from someone checking homework. That is why each mode prints its working: the standard form, the integrating factor or the characteristic equation, the general solution with its constants CC, C1C_1, C2C_2, the values fitted to the initial conditions, and the final value. Compare your own lines with these to find exactly where a sign slipped.

The page is also a differential equation solution calculator in the practical sense: it evaluates the solution at any point, gives the slope y′y' there, and tabulates the curve. For derivatives and antiderivatives of the formulas themselves, use the derivative calculator and the integral calculator; to plot other functions, the graphing calculator.

Existence, uniqueness and when to go numerical

If f(x,y)f(x, y) and ∂f/∂y\partial f/\partial y are continuous near (x0,y0)(x_0, y_0), the initial value problem y′=f(x,y)y' = f(x, y), y(x0)=y0y(x_0) = y_0 has exactly one solution on some interval around x0x_0 (the Picard–Lindelöf theorem). The linear equations on this page have continuous coefficients everywhere, so their solutions exist and are unique for all xx.

Uniqueness can fail: y′=∣y∣y' = \sqrt{|y|} with y(0)=0y(0) = 0 has the solution y=0y = 0 but also y=x2/4y = x^2/4 for x≥0x \ge 0. A solution can also blow up in finite time — y′=y2y' = y^2, y(0)=1y(0) = 1 gives y=1/(1−x)y = 1/(1 - x), which explodes at x=1x = 1; the solver stops with an error when the values explode instead of printing a meaningless number.

Most equations, such as y′=x2+y2y' = x^2 + y^2, have no formula in elementary functions. Then RK4 is the standard tool: with 100 steps it is usually accurate to many digits on a short interval. If halving hh (doubling nn) barely changes the result, you can trust it.

Frequently asked questions

What is a differential equation?

An equation that contains an unknown function and its derivatives, such as y′ = 3y or y″ + y = 0. Its solution is a function, not a number. The order is the highest derivative that appears; “ordinary” means one independent variable.

Why do I need initial conditions?

Integration produces arbitrary constants: one for a first-order equation, two for a second-order one. Each initial condition — y(x₀), and y′(x₀) for second order — fixes one constant, so you get a single particular solution instead of a whole family.

Can this diff eq solver handle non-linear equations?

Yes, in the numerical mode. Type any f(x, y), for example x*y^2 or sin(y) - x, and RK4 integrates it step by step. The closed-form modes cover the linear constant-coefficient and logistic cases, which have exact formulas.

How accurate is RK4 compared with Euler’s method?

For y′ = y over [0, 1], 100 RK4 steps match e to about 10 significant digits, while Euler is off by 0.0135. Halving the step divides the RK4 error by about 16 and the Euler error by only about 2.

What do complex roots mean physically?

Oscillation. For a y″ + b y′ + c y = 0 with roots α ± βi, the solution oscillates with angular frequency β; α < 0 means it dies out (a damped spring), α = 0 means it oscillates forever, and α > 0 means it grows.

Sources

Last updated:

More Math calculators

People also use