当前位置: 首页>>代码示例>>Golang>>正文


Golang cmplx.Pow函数代码示例

本文整理汇总了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
}
开发者ID:laysakura,项目名称:tour-of-go,代码行数:7,代码来源:048.go

示例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
}
开发者ID:heydabop,项目名称:go-tour,代码行数:7,代码来源:cbrt.go

示例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
}
开发者ID:kamilsmuga,项目名称:golang-tour,代码行数:7,代码来源:50-complex-cube-roots.go

示例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
}
开发者ID:houhlin,项目名称:learning-go,代码行数:7,代码来源:48.go

示例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
}
开发者ID:phoeagon,项目名称:go-tour,代码行数:7,代码来源:50.go

示例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))
}
开发者ID:utzig,项目名称:playground,代码行数:8,代码来源:complex_cube_roots.go

示例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
}
开发者ID:zeropol2,项目名称:Plalab_Go,代码行数:20,代码来源:practice05.go

示例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
}
开发者ID:jd1123,项目名称:gotourexercises,代码行数:9,代码来源:50.go

示例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
}
开发者ID:pewniak747,项目名称:go-tour,代码行数:9,代码来源:cbrt.go

示例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
}
开发者ID:robert-impey,项目名称:CodingExperiments,代码行数:9,代码来源:cbrt.go

示例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
		}
	}
}
开发者ID:rangilin,项目名称:go-tour-exercises,代码行数:10,代码来源:exercise-50.go

示例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
	}
}
开发者ID:py0n,项目名称:a_tour_of_go,代码行数:10,代码来源:48.go

示例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
}
开发者ID:brettanomyces,项目名称:ici,代码行数:10,代码来源:tour47.go

示例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
}
开发者ID:simbapeer,项目名称:study,代码行数:10,代码来源:complex_cube_roots.go

示例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
}
开发者ID:ohookins,项目名称:sevenlanguages,代码行数:11,代码来源:49.go


注:本文中的math/cmplx.Pow函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。