Differential equation calculator: first and second order
A differential equation links a function to its derivatives, such as dy/dx = x − y, and solving it means finding the function y. This differential equation calculator solves first order equations y′ = f(x, y) by direct integration, separation of variables or an integrating factor, and second order equations ay″ + by′ + cy = f(x) with constant coefficients. Give it a starting point and it shows the general solution, the particular solution through that point, every step, and the curve drawn on a slope field.
Differential Equation Solver
Solve first and second order equations and plot the solutions
What the differential equation solver does
- First order: you type the right side of y′ = f(x, y). It tries direct integration (no y on the right), separation of variables, then an integrating factor, and names the method it used.
- Second order: you type the numbers a, b and c in ay″ + by′ + cy, and the right side as a function of x. It solves the auxiliary equation, and for a right side made of polynomials, exponentials, sines and cosines it finds the particular integral by undetermined coefficients.
- The answer: the particular solution, the general solution with its constant, and the working line by line.
- The graph: for first order, a slope field with your solution and the curves from nearby starting points. For second order, the solution against x, or the phase plane (y′ against y) when the right side is 0.
- A numeric check: it also runs the fourth order Runge Kutta method (RK4) and shows its value of y one unit after the start next to the exact value. When no exact method works, the RK4 curve is the answer.
How to use the calculator
- Open the Differential Equation Solver and choose First order or Second order.
- For first order, type the right side after y′ =, using only x and y. For second order, type a, b and c in the boxes labelled y″, y′ and y, then the Right side, in x (0 if there is none).
- Under Starting point, type x and y. For second order, type the starting slope y′ too.
- Read the solution, the method, the general solution and the working. Drag the starting point on the graph to move it. On a slope field or the phase plane you can also tap anywhere to start from there.
- To practise, press Random problem: it sets a first or second order equation with a starting value and asks for y(1).
Write the equation with y′ on its own first. For 2y′ + 4y = 6, divide by 2 and move 4y across: y′ = 3 − 2y. Use x and y as the variables even when your problem uses t or T: the calculator reads x as the independent variable.
The methods behind it
Separable differential equations
If the right side splits into a part in x times a part in y, move all the y terms to the left with dy and the x terms to the right with dx, then integrate both sides and add one constant:
Integrating factor
A linear first order equation can be written y′ + P(x)y = Q(x). Multiply through by μ = e∫P dx. The left side becomes the derivative of μy, so μy = ∫μQ dx + C.
Second order: the auxiliary equation
For ay″ + by′ + cy = 0, try y = erx. That gives ar² + br + c = 0. Its roots decide the form of the general solution:
| Roots of ar² + br + c = 0 | General solution |
|---|---|
| Two real roots r₁ and r₂ | y = C₁e^(r₁x) + C₂e^(r₂x) |
| One repeated root r | y = (C₁ + C₂x)e^(rx) |
| Complex roots α ± βi | y = e^(αx)(C₁ cos βx + C₂ sin βx) |
With a right side f(x), add a particular integral: a guess shaped like f(x), with an extra factor of x if it clashes with the solution above. The two constants come from the starting values y(x₀) and y′(x₀).
Worked examples you can check in the calculator
Example 1: a separable equation
Solve dy/dx = x/y with y(0) = 2. Type x/y after y′ = and start at (0, 2). Separating gives y dy = x dx, and integrating both sides:
At x = 0, y = 2, so 2C = 4 and the positive root is the one through the point: y = √(x² + 4). The calculator shows y(1) = 2.236068 from both RK4 and the exact solution, which is √5.
Example 2: Newton's law of cooling
A cup of tea at 80 °C cools in a 20 °C room following dT/dt = −0.2(T − 20), with t in minutes. With x for time and y for temperature, type −0.2(y − 20) and start at (0, 80). The calculator separates the variables and gives
After 5 minutes the tea is 20 + 60e−1 = 42.1 °C. It reaches 40 °C when e−x/5 = 1/3, at x = 5 ln 3 = 5.49 minutes. The curve levels off towards 20 °C, the room temperature, and the slope field shows every starting temperature heading there.
Here x is the time in minutes and y is the temperature in °C.
Example 3: an integrating factor
The calculator opens on y′ = x − y with y(0) = 1. Written as y′ + y = x, P(x) = 1, so μ = ex and (exy)′ = xex. Integrating by parts gives exy = ex(x − 1) + C, so y = Ce−x + x − 1. The start gives C = 2:
The integration by parts step is shown in full, with u = x and dv = ex dx.
Example 4: second order, two real roots
Solve y″ + 5y′ + 4y = 0 with y(0) = 2 and y′(0) = 1. Choose Second order, type 1, 5 and 4, leave the right side as 0, and start at x = 0, y = 2, y′ = 1. Factorising r² + 5r + 4 as (r + 1)(r + 4) gives r = −1 or r = −4, so y = C₁e−x + C₂e−4x. Then y(0) = C₁ + C₂ = 2 and y′(0) = −C₁ − 4C₂ = 1, so C₁ = 3 and C₂ = −1: y = 3e−x − e−4x. The calculator shows y(1) = 1.085323.
Example 5: complex roots, a damped wave
The second order mode opens on y″ + 2y′ + 5y = 0. With y(0) = 1 and y′(0) = 0, the roots are −1 ± 2i and the solution is
The e−x shrinks the wave each cycle: this is a damped oscillation, like a spring with friction. Switch to Phase plane to see the path of (y, y′) spiral in to the origin.
Example 6: a right side, undetermined coefficients
Solve y″ − y = x with y(0) = 0 and y′(0) = 0. Type 1, 0 and −1, and x as the right side. The complementary function is C₁ex + C₂e−x. Guessing yp = Ax + B and substituting gives yp = −x. The starting values then give C₁ = 1/2 and C₂ = −1/2, so y = ex/2 − x − e−x/2.
Try one
What the calculator can't solve
It covers the standard methods above, not everything. When it can't find an exact solution it says so, and the curve comes from RK4 instead. For example, y′ = x + y² has no exact answer from these methods, and the calculator gives RK4's y(1) = 0.5571618 from y(0) = 0. These are outside it:
- Bernoulli equations and other non-linear ones that don't separate, such as y′ = y − xy². You get the RK4 curve only. By hand, substitute v = y−1 to make it linear.
- Second order equations with x in the coefficients, such as x²y″ + xy′ − y = 0. Only constant a, b and c are allowed.
- Right sides like tan x or ln x. Undetermined coefficients doesn't apply; variation of parameters is the by-hand method.
- Third order and higher, systems of equations, partial differential equations and Laplace transforms.
- Boundary values, such as y(0) = 0 and y(1) = 2. It needs y and y′ at one starting point.
Slope fields
A slope field draws a short line at each point with the slope dy/dx would have there. Solution curves follow the lines. Slope fields and separable equations make up Unit 7 of AP Calculus AB, which is 5% to 10% of the exam score. Practise reading them by tapping different starting points in the calculator and watching the curve follow the field.
Common mistakes
- Forgetting the constant. Add + C when you integrate, and only once: one constant covers both sides.
- Adding C after exponentiating. From ln|y| = kx + C, y = Aekx, not ekx + C.
- Separating a sum. y′ = x + y is not separable. It is linear, so use an integrating factor.
- The wrong sign in the auxiliary equation. (r + 1)(r + 4) = 0 gives r = −1 and r = −4, not 1 and 4.
- Too few starting values. A second order equation needs both y and y′ at the start to fix two constants.
- Missing the extra x. If the guess for the particular integral already appears in the complementary function, multiply it by x.
Related calculators
Solving almost always comes down to an integral. The integral calculator guide covers the rules, the integration by parts guide covers the step in Example 3, and the partial fraction decomposition guide covers the step that equations like y′ = y(1 − y) need.
Common questions
How do you solve a differential equation?
What is the difference between a general and a particular solution?
Can the calculator solve second order differential equations?
What is RK4?
Does it do Euler's method?
How do I type dy/dx?
Revision cards
Read the front, say your answer, then flip to check.
Where to go next
- Solve it
Differential Equation Solver
Solve first and second order equations and plot the solutions
Open the tool - Learn it
Calculus
Differentiation, integration and the mathematics that drives physics and engineering
Start the course - Test it
AP Calculus AB
A new exam-style paper every day, with instant marking and a mark scheme
Start today's paper