I don’t know if there is a better, more numerically stable way to do this calculation but I think the error is that you don’t initialize gb
before using it in the loop condition: while (abs(gb) >= 1e-12)
. Try setting gb
beforehand to a value > 1e-12, to make sure the loop executes at least once as in the R code.
1 Like