Last active
December 11, 2019 11:12
-
-
Save siisee11/8ee92a778906747dd7559e0f22ed34eb to your computer and use it in GitHub Desktop.
Complex cube roots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/cmplx" | |
) | |
func Cbrt(x complex128) complex128 { | |
var z complex128 = 1 | |
for i := 0 ; i < 50 ; i++ { | |
z = z - (z * z * z - x) / (3 * z * z) | |
} | |
return z | |
} | |
func main() { | |
fmt.Println(Cbrt(2)) | |
fmt.Println(cmplx.Pow(Cbrt(2), 3)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment