Created
December 25, 2013 01:18
-
-
Save kaipakartik/8119359 to your computer and use it in GitHub Desktop.
Advanced Exercise: Complex cube roots
http://tour.golang.org/#48
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" | |
"math/cmplx" | |
) | |
func Cbrt(x complex128) complex128 { | |
z := complex128(1) | |
for i := 0; i < 10; i++ { | |
z = z - (z*z*z - x)/(3 * z *z) | |
} | |
return z | |
} | |
func main() { | |
fmt.Println(Cbrt(2 + 3i), cmplx.Pow(2.0 + 3i, 1.0/3)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment