All problems
Newton Fractal Step
Problem
Take one Newton step of p(z) = z^2 - 2 for the complex number z given as [re, im].
The update is z_new = z - (z^2 - 2) / (2z). Implement complex arithmetic with pairs and return the result as [re, im]. Assume z is not zero.
Hint
Divide complex numbers by multiplying numerator and denominator by the conjugate.
Test cases
case 1
in: [[1,0]]
expected: [1.5,0]
case 2
in: [[1,1]]
expected: [1,0]
case 3
in: [[0,1]]
expected: [0,-0.5]
case 4
in: [[2,0]]
expected: [1.5,0]
Starter codePython
def newton_fractal_step(z):
# z is [re, im]; return [re, im]
# Your code here
pass4 test cases · run your code against them in the editor