The The Mirror Equation works for thin lenses too, with one change in where things are. For a lens, a real image forms on the far side, where the light goes, so that is where $d_i > 0$. Everything else, including the magnification, carries over from Lenses and Ray Diagrams.
Key idea
$$\frac{1}{f} = \frac{1}{d_o} + \frac{1}{d_i}, \qquad m = -\frac{d_i}{d_o}.$$ $f > 0$ for a converging lens, $f < 0$ for a diverging lens. $d_i > 0$: real image on the far side. $d_i < 0$: virtual image on the object's side.
Why it works
The same similar triangles as for a mirror appear. The ray through the center goes straight, so the object and image tips line up through the center: $\frac{h_i}{h_o} = -\frac{d_i}{d_o}$. The parallel ray bends through $F$, giving $\frac{h_i}{h_o} = -\frac{d_i - f}{f}$. Setting them equal gives the same equation. The geometry is a mirror unfolded.
Common mistake
Forgetting that a diverging lens has a negative focal length. A diverging lens with "$f = 20\ \text{cm}$" means $f = -20\ \text{cm}$ in the equation. Check: a diverging lens alone always gives $d_i < 0$ and $0 < m < 1$.
Worked example: Converging lens
An object is $7.5\ \text{cm}$ from a converging lens with $f = 5.0\ \text{cm}$. Find $d_i$ and $m$.
- $\dfrac{1}{d_i} = \dfrac{1}{5.0} - \dfrac{1}{7.5} = \dfrac{3}{15} - \dfrac{2}{15} = \dfrac{1}{15}$.
- $d_i = 15\ \text{cm}$: a real image on the far side.
- $m = -\dfrac{15}{7.5} = -2.0$: inverted and twice as tall.
Answer: $d_i = 15\ \text{cm}$, $m = -2.0$
Worked example: Diverging lens
An object is $30\ \text{cm}$ from a diverging lens with $f = -20\ \text{cm}$.
- $\dfrac{1}{d_i} = -\dfrac{1}{20} - \dfrac{1}{30} = -\dfrac{3}{60} - \dfrac{2}{60} = -\dfrac{5}{60}$.
- $d_i = -12\ \text{cm}$: virtual, on the object's side.
- $m = -\dfrac{-12}{30} = +0.40$: upright and smaller.
Answer: $d_i = -12\ \text{cm}$, $m = +0.40$
Worked example: Choosing a projector lens
A projector puts a slide $10.0\ \text{cm}$ from its lens and a sharp image on a screen $4.0\ \text{m}$ away. What focal length does the lens have?
- Both distances are real: $d_o = 0.100\ \text{m}$, $d_i = 4.0\ \text{m}$.
- $$\dfrac{1}{f} = \dfrac{1}{0.100} + \dfrac{1}{4.0} = 10.0 + 0.25 = 10.25\ \text{m}^{-1}.$$
- $f = 0.0976\ \text{m} = 9.76\ \text{cm}$. The magnification is $m = -40$, so the slide is turned upside down to come out upright.
Answer: $f \approx 9.8\ \text{cm}$
Optometrists use the power $P = 1/f$ in diopters (with $f$ in meters): a $+2.5\ \text{D}$ reading lens has $f = 40\ \text{cm}$.