Skip to content
Family Table Math

Separation of Variables

So far you have checked solutions that someone handed you. Now you will find them yourself. Separation of variables solves a big family of differential equations by moving everything with yy to one side, everything with xx to the other, and integrating. It is the main solving method in AP Calculus AB, and a separation-of-variables question appears on the free-response section most years.

A differential equation is separable if the right side can be written as a function of xx times a function of yy:

dydx=g(x) h(y)\frac{dy}{dx} = g(x)\,h(y)

For example, dydx=2xy\dfrac{dy}{dx} = 2xy, dydx=x2y2\dfrac{dy}{dx} = \dfrac{x^2}{y^2}, and dydx=ex+y=exey\dfrac{dy}{dx} = e^{x + y} = e^x e^y are separable. But dydx=x+y\dfrac{dy}{dx} = x + y is not: you can’t split a sum into a product.

  1. Separate: get all the yy‘s (with dydy) on one side and all the xx‘s (with dxdx) on the other, giving 1h(y) dy=g(x) dx\dfrac{1}{h(y)}\,dy = g(x)\,dx.
  2. Integrate both sides. Write one constant of integration, +C+ C, on the xx side.
  3. Use the initial condition (if there is one) to find CC. It is usually easiest to do this right after integrating, before solving for yy.
  4. Solve for yy if you can.
  5. Check by substituting back into the differential equation and the initial condition.

You will often need u-substitution for the integrals, and ∫1y dy=ln⁡∣y∣+C\displaystyle\int \frac{1}{y}\,dy = \ln|y| + C comes up all the time.

When you get ln⁡∣y∣=(something)+C\ln|y| = (\text{something}) + C, exponentiate both sides:

∣y∣=e(something)+C=eC⋅e(something)|y| = e^{(\text{something}) + C} = e^C \cdot e^{(\text{something})}

Since eCe^C is just a positive constant, and the absolute value allows either sign, you can write y=Ae(something)y = Ae^{(\text{something})} for a constant AA. Then use the initial condition to find AA.

A particular solution must be differentiable on an open interval that contains the initial xx-value. If your formula has a vertical asymptote, a square root of a negative number, or a ln⁡\ln of a non-positive number somewhere, the solution only lives on the piece that contains the starting point. AP questions sometimes ask for this domain.

Find the general solution of dydx=x2y2\dfrac{dy}{dx} = \dfrac{x^2}{y^2}.

Solution. Multiply both sides by y2 dxy^2\,dx to separate:

y2 dy=x2 dxy^2\,dy = x^2\,dx

Integrate both sides, with one constant:

y33=x33+C\frac{y^3}{3} = \frac{x^3}{3} + C

Multiply by 33. Since 3C3C is still just an arbitrary constant, call it CC again:

y3=x3+C⇒y=x3+C3y^3 = x^3 + C \quad\Rightarrow\quad y = \sqrt[3]{x^3 + C}

Solve dydx=2xy\dfrac{dy}{dx} = 2xy with y(0)=3y(0) = 3.

Solution. Separate and integrate:

1y dy=2x dx∫1y dy=∫2x dxln⁡∣y∣=x2+C\begin{aligned} \frac{1}{y}\,dy &= 2x\,dx \\ \int \frac{1}{y}\,dy &= \int 2x\,dx \\ \ln|y| &= x^2 + C \end{aligned}

Use the initial condition now: ln⁡3=0+C\ln 3 = 0 + C, so C=ln⁡3C = \ln 3. Then

∣y∣=ex2+ln⁡3=eln⁡3 ex2=3ex2|y| = e^{x^2 + \ln 3} = e^{\ln 3}\,e^{x^2} = 3e^{x^2}

Since y(0)=3y(0) = 3 is positive, y=3ex2y = 3e^{x^2}.

Check: dydx=3ex2⋅2x=2x(3ex2)=2xy\dfrac{dy}{dx} = 3e^{x^2} \cdot 2x = 2x\big(3e^{x^2}\big) = 2xy ✓, and y(0)=3e0=3y(0) = 3e^0 = 3 ✓.

Example 3: A solution with a restricted domain

Section titled “Example 3: A solution with a restricted domain”

Solve dydx=y2\dfrac{dy}{dx} = y^2 with y(0)=1y(0) = 1, and state the domain of the solution.

Solution. Separate and integrate:

y−2 dy=dx⇒−1y=x+Cy^{-2}\,dy = dx \quad\Rightarrow\quad -\frac{1}{y} = x + C

At (0,1)(0, 1): −1=0+C-1 = 0 + C, so C=−1C = -1. Then

−1y=x−1⇒y=−1x−1=11−x-\frac{1}{y} = x - 1 \quad\Rightarrow\quad y = \frac{-1}{x - 1} = \frac{1}{1 - x}

This formula has a vertical asymptote at x=1x = 1. The solution must live on an open interval containing the starting value x=0x = 0, so its domain is x<1x \lt 1.

Graph of y = 1/(1 - x). The solid branch to the left of the vertical asymptote x = 1 passes through (0, 1) and shoots upward as x approaches 1. The dashed branch to the right of x = 1 is not part of the particular solution. −2 −1 1 2 3 −3 −2 −1 1 2 3 4 (0, 1) x = 1 y = 1/(1 − x)
Only the branch through (0,1)(0, 1), where x<1x \lt 1, is the particular solution. The dashed branch is not part of it.

Notice that nothing in the equation dydx=y2\dfrac{dy}{dx} = y^2 hints at trouble at x=1x = 1. The solution “blows up” there anyway, because it grows faster and faster.

Solve dydx=xcos⁡(x2)y\dfrac{dy}{dx} = \dfrac{x\cos(x^2)}{y} with y(0)=2y(0) = 2 (radians).

Solution. Separate:

y dy=xcos⁡(x2) dxy\,dy = x\cos(x^2)\,dx

For the right side, let u=x2u = x^2, so du=2x dxdu = 2x\,dx and x dx=12 dux\,dx = \tfrac{1}{2}\,du:

∫xcos⁡(x2) dx=12∫cos⁡u du=12sin⁡(x2)+C\int x\cos(x^2)\,dx = \frac{1}{2}\int \cos u\,du = \frac{1}{2}\sin(x^2) + C

So

y22=12sin⁡(x2)+C\frac{y^2}{2} = \frac{1}{2}\sin(x^2) + C

At (0,2)(0, 2): 42=12sin⁡0+C\dfrac{4}{2} = \dfrac{1}{2}\sin 0 + C, so C=2C = 2. Multiply by 22:

y2=sin⁡(x2)+4y^2 = \sin(x^2) + 4

Since y(0)=2y(0) = 2 is positive, take the positive square root:

y=sin⁡(x2)+4y = \sqrt{\sin(x^2) + 4}

Because sin⁡(x2)≥−1\sin(x^2) \ge -1, the expression under the root is always at least 33, so this solution is defined for all real xx.

Forgetting +C+ C, or adding it at the end. The constant must appear as soon as you integrate. Writing ln⁡∣y∣=x2\ln|y| = x^2 and then y=ex2+Cy = e^{x^2} + C gives the wrong family. On AP free-response questions, a missing constant of integration usually costs the remaining points for that part, so build the habit now.

Separating a sum. dydx=x+y\dfrac{dy}{dx} = x + y can’t be split into dydy terms and dxdx terms by multiplying or dividing. Only products and quotients separate. On the AP exam, an incorrect separation usually means no credit for the rest of the problem.

Exponentiating term by term. From ln⁡∣y∣=x2+C\ln|y| = x^2 + C, the next step is ∣y∣=ex2+C=eCex2|y| = e^{x^2 + C} = e^C e^{x^2}, not y=ex2+eCy = e^{x^2} + e^C.

Picking the wrong square root. When you solve y2=…y^2 = \dots, use the initial condition to choose the sign. If y(0)=−3y(0) = -3, the solution is the negative square root.

Ignoring the domain. A particular solution can’t jump across an asymptote or a gap. State the interval that contains the initial xx-value.

Not checking. Differentiating your answer and substituting it back takes a minute and catches most algebra slips.

1. (Warm-up) Which of these differential equations are separable?

  • (a) dydx=xy2\dfrac{dy}{dx} = xy^2
  • (b) dydx=x+y\dfrac{dy}{dx} = x + y
  • (c) dydx=ex+y\dfrac{dy}{dx} = e^{x + y}
  • (d) dydx=y+1x2\dfrac{dy}{dx} = \dfrac{y + 1}{x^2}
Solution

(a) Separable: 1y2 dy=x dx\dfrac{1}{y^2}\,dy = x\,dx.

(b) Not separable: a sum of xx and yy doesn’t factor into a function of xx times a function of yy.

(c) Separable: ex+y=exeye^{x + y} = e^x e^y, so e−y dy=ex dxe^{-y}\,dy = e^x\,dx.

(d) Separable: 1y+1 dy=1x2 dx\dfrac{1}{y + 1}\,dy = \dfrac{1}{x^2}\,dx.

2. (Warm-up) Find the general solution of dydx=xy\dfrac{dy}{dx} = \dfrac{x}{y}.

Solutiony dy=x dx⇒y22=x22+C⇒y2=x2+Cy\,dy = x\,dx \quad\Rightarrow\quad \frac{y^2}{2} = \frac{x^2}{2} + C \quad\Rightarrow\quad y^2 = x^2 + C

(The constant 2C2C was renamed CC.)

3. (Core) Solve dydx=3y\dfrac{dy}{dx} = 3y with y(0)=4y(0) = 4.

Solution1y dy=3 dx⇒ln⁡∣y∣=3x+C\frac{1}{y}\,dy = 3\,dx \quad\Rightarrow\quad \ln|y| = 3x + C

At (0,4)(0, 4): ln⁡4=C\ln 4 = C. So ∣y∣=e3x+ln⁡4=4e3x|y| = e^{3x + \ln 4} = 4e^{3x}, and since y(0)>0y(0) \gt 0,

y=4e3xy = 4e^{3x}

Check: dydx=12e3x=3(4e3x)=3y\dfrac{dy}{dx} = 12e^{3x} = 3(4e^{3x}) = 3y ✓.

4. (Core) Solve dydx=2x+12y\dfrac{dy}{dx} = \dfrac{2x + 1}{2y} with y(0)=−3y(0) = -3.

Solution2y dy=(2x+1) dx⇒y2=x2+x+C2y\,dy = (2x + 1)\,dx \quad\Rightarrow\quad y^2 = x^2 + x + C

At (0,−3)(0, -3): 9=0+0+C9 = 0 + 0 + C, so C=9C = 9 and y2=x2+x+9y^2 = x^2 + x + 9.

Since y(0)=−3y(0) = -3 is negative, take the negative root:

y=−x2+x+9y = -\sqrt{x^2 + x + 9}

The quadratic x2+x+9x^2 + x + 9 has discriminant 1−36<01 - 36 \lt 0, so it is always positive and the solution is defined for all real xx.

5. (Core) Solve dydx=xy2\dfrac{dy}{dx} = xy^2 with y(0)=1y(0) = 1, and state the domain of the solution.

Solutiony−2 dy=x dx⇒−1y=x22+Cy^{-2}\,dy = x\,dx \quad\Rightarrow\quad -\frac{1}{y} = \frac{x^2}{2} + C

At (0,1)(0, 1): −1=C-1 = C. So

−1y=x22−1=x2−22⇒y=22−x2-\frac{1}{y} = \frac{x^2}{2} - 1 = \frac{x^2 - 2}{2} \quad\Rightarrow\quad y = \frac{2}{2 - x^2}

The formula is undefined at x=±2x = \pm\sqrt{2}. The interval containing x=0x = 0 is

−2<x<2-\sqrt{2} \lt x \lt \sqrt{2}

6. (Core) Solve dydx=ycos⁡x\dfrac{dy}{dx} = y\cos x with y(0)=2y(0) = 2 (radians). Then find y(π2)y\left(\dfrac{\pi}{2}\right), exactly and to 3 decimal places.

Solution1y dy=cos⁡x dx⇒ln⁡∣y∣=sin⁡x+C\frac{1}{y}\,dy = \cos x\,dx \quad\Rightarrow\quad \ln|y| = \sin x + C

At (0,2)(0, 2): ln⁡2=0+C\ln 2 = 0 + C. So ∣y∣=esin⁡x+ln⁡2=2esin⁡x|y| = e^{\sin x + \ln 2} = 2e^{\sin x}, and since y(0)>0y(0) \gt 0,

y=2esin⁡xy = 2e^{\sin x}

Then y(π2)=2e1=2e≈5.437y\left(\dfrac{\pi}{2}\right) = 2e^{1} = 2e \approx 5.437.

7. (Core) A student solves dydx=2xy\dfrac{dy}{dx} = 2xy with y(0)=5y(0) = 5 like this:

ln⁡∣y∣=x2⇒y=ex2+C⇒5=1+C⇒y=ex2+4\ln|y| = x^2 \quad\Rightarrow\quad y = e^{x^2} + C \quad\Rightarrow\quad 5 = 1 + C \quad\Rightarrow\quad y = e^{x^2} + 4

Explain the error and find the correct solution.

Solution

The constant of integration has to appear when you integrate, not after solving for yy. The correct line is ln⁡∣y∣=x2+C\ln|y| = x^2 + C. (Check the student’s answer: y=ex2+4y = e^{x^2} + 4 gives dydx=2xex2\dfrac{dy}{dx} = 2xe^{x^2}, but 2xy=2xex2+8x2xy = 2xe^{x^2} + 8x. They don’t match.)

Correct work: at (0,5)(0, 5), ln⁡5=0+C\ln 5 = 0 + C, so ∣y∣=ex2+ln⁡5=5ex2|y| = e^{x^2 + \ln 5} = 5e^{x^2}, and

y=5ex2y = 5e^{x^2}

8. (Challenge) Solve dydx=y2x\dfrac{dy}{dx} = \dfrac{y^2}{x} with y(1)=−1y(1) = -1, and state the domain of the solution.

Solutiony−2 dy=1x dx⇒−1y=ln⁡∣x∣+Cy^{-2}\,dy = \frac{1}{x}\,dx \quad\Rightarrow\quad -\frac{1}{y} = \ln|x| + C

At (1,−1)(1, -1): 1=ln⁡1+C=C1 = \ln 1 + C = C. So

−1y=ln⁡∣x∣+1⇒y=−11+ln⁡∣x∣-\frac{1}{y} = \ln|x| + 1 \quad\Rightarrow\quad y = -\frac{1}{1 + \ln|x|}

The starting value x=1x = 1 is positive, and the equation is undefined at x=0x = 0, so we need x>0x \gt 0 (and ∣x∣=x|x| = x). We also need 1+ln⁡x≠01 + \ln x \ne 0, that is, x≠e−1x \ne e^{-1}. The interval containing x=1x = 1 is

x>1ex \gt \frac{1}{e}

so the solution is y=−11+ln⁡xy = -\dfrac{1}{1 + \ln x} for x>1ex \gt \dfrac{1}{e}.

Check: dydx=1/x(1+ln⁡x)2=1x⋅y2\dfrac{dy}{dx} = \dfrac{1/x}{(1 + \ln x)^2} = \dfrac{1}{x} \cdot y^2 ✓.

9. (Challenge) Solve dydx=1+y21+x2\dfrac{dy}{dx} = \dfrac{1 + y^2}{1 + x^2} with y(0)=1y(0) = 1. Write yy as a rational function of xx, and state its domain. (Hint: use tan⁡(A+B)=tan⁡A+tan⁡B1−tan⁡Atan⁡B\tan(A + B) = \dfrac{\tan A + \tan B}{1 - \tan A \tan B}.)

Solution11+y2 dy=11+x2 dx⇒arctan⁡y=arctan⁡x+C\frac{1}{1 + y^2}\,dy = \frac{1}{1 + x^2}\,dx \quad\Rightarrow\quad \arctan y = \arctan x + C

At (0,1)(0, 1): arctan⁡1=arctan⁡0+C\arctan 1 = \arctan 0 + C, so C=π4C = \dfrac{\pi}{4}. Take the tangent of both sides:

y=tan⁡(arctan⁡x+π4)=x+11−x⋅1=1+x1−xy = \tan\left(\arctan x + \frac{\pi}{4}\right) = \frac{x + 1}{1 - x \cdot 1} = \frac{1 + x}{1 - x}

The formula is undefined at x=1x = 1, and the interval containing x=0x = 0 is x<1x \lt 1.

Check: by the quotient rule, dydx=(1−x)+(1+x)(1−x)2=2(1−x)2\dfrac{dy}{dx} = \dfrac{(1 - x) + (1 + x)}{(1 - x)^2} = \dfrac{2}{(1 - x)^2}. Also 1+y2=(1−x)2+(1+x)2(1−x)2=2(1+x2)(1−x)21 + y^2 = \dfrac{(1 - x)^2 + (1 + x)^2}{(1 - x)^2} = \dfrac{2(1 + x^2)}{(1 - x)^2}, so 1+y21+x2=2(1−x)2\dfrac{1 + y^2}{1 + x^2} = \dfrac{2}{(1 - x)^2} ✓.