Magnification M is defined as :

**M = - q / p**

(*where q=image distance, p=object distance)

we can further solve this equation for **q**, (which is needed later on).

**q = - M*p**

Based on the properties on lens, we can conclude that for M<1 it is a diverging lens, and the image is virtual.

Here are some basic sign conventions for reference:

the distance between the object and its image is given by **d.**

For M < 1, we will have

**d = p + q**

substituting in q we get:

**d = p + -M*p**

solving for p we get:

**p = d / (1-M)**

We can now plug in p and q into the thing lens equation to solve for f:

**1/p + 1/q = 1/f **

**(1-M)/ d + 1/-M*p = 1/f**

solving for f we get:

The steps for solving M>1 is pretty much the same.

only this time you have a converging lens, and the image is still virtual. So we get that

**d = -q - p**

All the other steps are exactly the same as earlier. the final solution will be: