your objective is
J = (.5*w-target)/2 #divicion is because of meam dJ/dw = d(.25*w+target/2)/dw = .25
see, no problem.