Created
September 25, 2014 10:48
-
-
Save kei-s/2d4f47f9c5ffee6a5e48 to your computer and use it in GitHub Desktop.
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" | |
import "math/cmplx" | |
func Cbrt(x complex128) complex128 { | |
z := 1 + 0i | |
for { | |
zz := z - ((z * z * z - x) / (3 * z * z)) | |
if cmplx.Abs(z-zz) < 0.0000001 { | |
return z | |
} | |
z = zz | |
} | |
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