Created
September 13, 2014 04:27
-
-
Save oldergod/cbf2d8cec608e86d905e to your computer and use it in GitHub Desktop.
Tour of Go Complex Cube Roots
This file contains hidden or 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, z complex128) complex128 { | |
| for i := 0; i < 10; i++ { | |
| z = z - (cmplx.Pow(z, 3)-x)/(3*cmplx.Pow(z, 2)) | |
| } | |
| return z | |
| } | |
| func main() { | |
| var r complex128 = Cbrt(2, 1) | |
| fmt.Println(r) | |
| fmt.Println(cmplx.Pow(r, 3)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment