I'm trying to make an adjustable voltage output circuit that can swing from 0-40V... I'm planning on using a LM317HV and was going to use one of the circuits from their datasheet:

So, I tried to see what's going on here, and I figure it's

Vout = 1.25V + 1.25(R2/R1) - 1.2

which (if my equation is right) would give me approx 0V when R2=0, but when R2 = 5k.... I get.... Vout=41.7V...

so my questions are... is my equation wrong? is it possible to modify this circuit so it can give 0-40V out?

much thanks!