Skip to content

Instantly share code, notes, and snippets.

@siisee11

siisee11/exercise5.go

Last active Dec 11, 2019
Embed
What would you like to do?
Complex cube roots
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