本文整理汇总了Golang中math/cmplx.Pow函数的典型用法代码示例。如果您正苦于以下问题:Golang Pow函数的具体用法?Golang Pow怎么用?Golang Pow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Pow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Cbrt
func Cbrt(x complex128) complex128 {
z := 1.0 + 0i
for i := 0; i < 50; i++ {
z = z - (cmplx.Pow(z, 3)-x)/(3.0*cmplx.Pow(z, 2))
}
return z
}
示例2: cbrt
func cbrt(x complex128) complex128 {
z := x
for i := 0; i < 10; i++ {
z -= (cmplx.Pow(z, 3) - x) / (3 * cmplx.Pow(z, 2))
}
return z
}
示例3: Cbrt
func Cbrt(x complex128) complex128 {
z := complex128(1)
for i := 0; i < 10; i++ {
z = z - ((cmplx.Pow(z, 3) - x) / (3 * cmplx.Pow(z, 2)))
}
return z
}
示例4: Cbrt
func Cbrt(x complex128) complex128 {
var z complex128 = 1.0
for i := 0; i < 10; i++ {
z = z - (cmplx.Pow(z, 3)-x)/(3*cmplx.Pow(z, 2))
}
return z
}
示例5: Cbrt
func Cbrt(x complex128) complex128 {
z := x
for i := 0; i < 10; i += 1 {
z = z - (cmplx.Pow(z, 3)-x)/(3*cmplx.Pow(z, 2))
}
return z
}
示例6: main
func main() {
x := Cbrt(2)
fmt.Println(x)
fmt.Println(cmplx.Pow(x, 3))
x = Cbrt(complex(2, 2))
fmt.Println(x)
fmt.Println(cmplx.Pow(x, 3))
}
示例7: Cbrt
/*
* 뉴턴의 방법 참고
* https://en.wikipedia.org/wiki/Newton%27s_method
* http://ntalbs.github.io/2014/07/25/newtons-method/
* http://nosyu.pe.kr/1169
* f(x) = x^3 - X 에서 시작.
* xn+1 = xn - (xn^3 - X) / 3xn^2
* 초기값은 1로
* 실제 2의 3제곱근은 1.259921049894873
* 5의 3제곱근은 1.709975946676697
*
*/
func Cbrt(x complex128) complex128 {
var result complex128 = 1
for i := 0; i < 10; i++ {
result = result - ((cmplx.Pow(result, 3) - x) / (3 * cmplx.Pow(result, 2)))
}
return result
}
示例8: Cbrt
func Cbrt(x complex128) complex128 {
z := complex128(1)
fmt.Println(z)
for i := 0; i < 28; i++ {
z = z - (cmplx.Pow(z, 3)-x)/(complex128(3)*cmplx.Pow(z, 3))
}
return z
}
示例9: MyCbrt
func MyCbrt(x complex128) complex128 {
z, prev_z := x, x+1
eps := math.Pow(10, -10)
for float64(cmplx.Abs(z-prev_z))-eps > 0 {
prev_z = z
z = z - (cmplx.Pow(z, 3)-x)/(3*cmplx.Pow(z, 3))
}
return z
}
示例10: Cbrt
func Cbrt(x complex128) complex128 {
z := complex128(1)
for i := 0; i < 5; i++ { // How do we calculate how many iterations we need for it not to change the output?
z -= (cmplx.Pow(z, complex128(3)) - x) / (3 * cmplx.Pow(z, complex128(2)))
}
return z
}
示例11: Cbrt
func Cbrt(x complex128) complex128 {
z := x
for {
pz := z
z = z - (cmplx.Pow(z, 3)-x)/(3*cmplx.Pow(z, 2))
if cmplx.Abs(pz-z) < 1e-31 {
return pz
}
}
}
示例12: cbrtByNewtonMethod
func cbrtByNewtonMethod(x complex128) complex128 {
z0 := x / 2
for {
z1 := z0 - (cmplx.Pow(z0, 3)-x)/(3*cmplx.Pow(z0, 2))
if cmplx.Abs(z1-z0) < 1e-15 {
return z1
}
z0 = z1
}
}
示例13: Cbrt
func Cbrt(x complex128) complex128 {
y := complex128(0)
z := complex128(1)
for y != z {
y = z
z = z - (cmplx.Pow(z, 3)-x)/(3*cmplx.Pow(z, 2))
}
return z
}
示例14: Cbrt
func Cbrt(x complex128) complex128 {
z := complex128(3)
for i := 0; i < 100; i++ {
temp := z
z = z - (cmplx.Pow(z, 3)-x)/(3*cmplx.Pow(z, 2))
temp = (z - temp)
temp = temp * temp
}
return z
}
示例15: Cbrt
func Cbrt(x complex128) complex128 {
z := complex128(1)
for {
y := z
z = z - (cmplx.Pow(z, 3)-x)/(3*cmplx.Pow(z, 2))
if cmplx.Abs(y-z) < 0.01 {
break
}
}
return z
}