Skip to content
DeepForgeby svx
All problems
MediumCalculusca-124

Erf Inverse Approximation

Problem

Approximate the inverse error function with n Newton iterations.

Starting from x0, repeatedly update x = x - (erf(x) - y) / ((2/sqrt(pi)) * e^(-x^2)). Given y in (-1, 1), x0, and the iteration count n, return the final value.

Hint

Newton converges quadratically here because the derivative erf'(x) is bounded away from zero.

Test cases

case 1
in: [0,0,5]
expected: 0
case 2
in: [0.5,0.5,6]
expected: 0.4769362762044698
case 3
in: [0.8427007929497149,0.5,10]
expected: 1
case 4
in: [-0.5,-0.5,6]
expected: -0.4769362762044698
case 5
in: [0.9,1,8]
expected: 1.1630871536766743
Starter codePython
def erfinv_newton(y, x0, n):
    # Your code here
    pass

5 test cases · run your code against them in the editor