A ray-tracing code for convex lens
This code reads in ho, xo of an object, focal length of a convex lense f.  As returns the object-len-image system is visualised, along with the location and magnification of the image.

(*xo=1.0;*)
ho=1.0;f=1.0;
Manipulate[
(*
ho=1;
u=Input["Value for object's distance from center of len, O, in cm"];
f=Input["Value of lense's focal lenght, in cm"];
*)

c={0,0};
BL={0,-1};TL={0,1};
BO:={xo,0};TO:={xo,ho};
BI:={xi,0};TI:={xi,hi};
FP:={-f,0};c:={0,0};

min=Min[-2ho,xo,xi,-2f];max=Max[2ho,xo,xi,2f];
lop={min,0};rop={max,0};

MD:=If[Abs[hi/ho]>1,"Magnified","Diminished"];
m:=Abs[hi/ho];
vorr:=If[xi*xo<0,"Real","Virtual"];
invorer:=If[hi*ho<0,"Inverted","Erected"];

xi:=xo*f/(f-xo);hi:=ho*f/(f-xo);TI:={xi,hi};BI:={xi,0};
plotlabel:=Column[{
{"f="<>ToString[f],
"xo="<>ToString[xo],
"ho="<>ToString[ho]},
{"m="<>ToString[m],MD,vorr,invorer}
}];

Graphics[{
{Dotted,Magenta,Line[{BL,TL}]},(* lense *)
Line[{lop,rop}],                                         (* optical axis *)
{Red,Line[{BI,TI}]},(* image *)
{Blue,Line[{BO,TO}]}, (* object *)
{PointSize->0.02,Point[{FP}]}, (* focal point *)
{Dotted,Line[{TO,{0,ho},FP,TI}]}(* ray from object's tip through FP *),
{Dotted,Line[{TO,c,TI}]}(* ray from object's tip throught c *)
},PlotLabel->plotlabel]

,{xo,0.1f,2.2f,0.2f}
](*end manipulate*)