Just build a NonlinearLeastSquaresProblem with that f and solve. Did you give that a try? How did it do?
f