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


Golang cmplx.Abs函数代码示例

本文整理汇总了Golang中math/cmplx.Abs函数的典型用法代码示例。如果您正苦于以下问题:Golang Abs函数的具体用法?Golang Abs怎么用?Golang Abs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Abs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: accumulateSeqence

func accumulateSeqence(bailout int, acc *accumulator) {

	// Find a sequence.
	var c complex128
	for {
		c = complex(rand.Float64()*4-2, rand.Float64()*4-2)
		var z complex128
		var i int
		for i < bailout && cmplx.Abs(z) <= 2 {
			z = z*z + c
			i++
		}
		if i == bailout {
			break
		}
	}

	// Accumulate the sequence.
	var z complex128
	var i int
	for i < bailout && cmplx.Abs(z) < 2 {
		z = z*z + c
		i++
		acc.increment(z)
	}
}
开发者ID:peterstace,项目名称:buddhabrotgen,代码行数:26,代码来源:main.go

示例2: logInterpolate

func logInterpolate(a complex128, b complex128, proportion float64) complex128 {
	// TODO - precalc arg/norm outside the loop.
	if cmplx.Abs(a) < cmplx.Abs(b) {
		return logInterpolate(b, a, 1-proportion)
	}

	z := b / a
	zArg := cmplx.Phase(z)
	if zArg > 0 {
		// aArg -> bArg, or aArg -> bArg + 2PI, whichever is closer
		if zArg > math.Pi {
			zArg -= 2 * math.Pi
		}
	} else {
		// aArg -> bArg, or aArg -> bArg - 2PI, whichever is closer
		if zArg < -math.Pi {
			zArg += 2 * math.Pi
		}
	}

	zLogAbs := math.Log(cmplx.Abs(z))
	cArg, cLogAbs := zArg*proportion, zLogAbs*proportion
	cAbs := math.Exp(cLogAbs)
	return a * cmplx.Rect(cAbs, cArg)
}
开发者ID:mantyr,项目名称:go-sound,代码行数:25,代码来源:spectrogram.go

示例3: TaxicabNorm

func (this *Matrix) TaxicabNorm() float64 {
	sum := make(chan complex128, 1)
	this.sumApplyFunction(0, len(this.A), sum, func(a complex128) float64 { return cmplx.Abs(a) })

	v := <-sum
	return cmplx.Abs(v)
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:7,代码来源:Norms.go

示例4: Pivot

//Pivot
func (this *Matrix) Pivot() (*Matrix, *Matrix) {
	pivot := this.Copy()
	if this.m == this.n {
		p := I(this.m)
		for j := 1; j <= this.m; j++ {
			max := cmplx.Abs(pivot.GetValue(j, j))
			row := j
			for i := j; i <= pivot.m; i++ {
				pvalue := pivot.GetValue(i, j)
				if cmplx.Abs(pvalue) > max {
					max = cmplx.Abs(pvalue)
					row = i
				}
			}
			if j != row {
				tj := this.GetRow(j)
				trow := this.GetRow(row)

				pivot.SetRow(j, trow)
				pivot.SetRow(row, tj)

				pj := p.GetRow(j)
				prow := p.GetRow(row)

				p.SetRow(j, prow)
				p.SetRow(row, pj)
			}
		}
		return p, pivot
	}
	return nil, nil
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:33,代码来源:Decompositions.go

示例5: Solve

// Solve is Gift wrapping algorithm
func Solve(ps []complex128) []complex128 {
	var chList []complex128
	a := nearest(ps)

	for {
		chList = append(chList, a)
		b := ps[0]

		for _, c := range ps[1:] {
			if a == b {
				b = c
				continue
			}

			p1, p2 := b-a, c-a
			v := product(p2, p1)
			if v > 0 || (v == 0 && cmplx.Abs(p2) > cmplx.Abs(p1)) {
				b = c
			}
		}

		a = b
		if a == chList[0] {
			break
		}
	}
	return chList
}
开发者ID:yukirin,项目名称:algo,代码行数:29,代码来源:convexhull.go

示例6: agm

func agm(a, g complex128) complex128 {
	for cmplx.Abs(a-g) > cmplx.Abs(a)*ε {
		a, g = (a+g)*.5, cmplx.Rect(math.Sqrt(cmplx.Abs(a)*cmplx.Abs(g)),
			(cmplx.Phase(a)+cmplx.Phase(g))*.5)
	}
	return a
}
开发者ID:travis1230,项目名称:RosettaCodeData,代码行数:7,代码来源:arithmetic-geometric-mean-2.go

示例7: eqEpsRel

func eqEpsRel(a, b complex128, eps float64) bool {
	if a == b {
		return true
	}
	// cmplx.Abs(a - b) / math.Max(cmplx.Abs(a), cmplx.Abs(b)) <= eps
	return cmplx.Abs(a-b) <= eps*math.Max(cmplx.Abs(a), cmplx.Abs(b))
}
开发者ID:jvlmdr,项目名称:lin-go,代码行数:7,代码来源:err.go

示例8: FrobeniusNorm

func (this *Matrix) FrobeniusNorm() float64 {
	sum := make(chan complex128, 1)
	this.sumApplyFunction(0, len(this.A), sum, func(a complex128) float64 { return cmplx.Abs(a) * cmplx.Abs(a) })

	v := <-sum

	return math.Sqrt(cmplx.Abs(v))
}
开发者ID:eddytrex,项目名称:AIgo,代码行数:8,代码来源:Norms.go

示例9: maxidx

func maxidx(row []complex128) int {
	idx, max := 0, cmplx.Abs(row[0])
	for i, v := range row {
		vAbs := cmplx.Abs(v)
		if vAbs > max {
			idx, max = i, vAbs
		}
	}
	return idx
}
开发者ID:mantyr,项目名称:go-sound,代码行数:10,代码来源:utils.go

示例10: invMandelbrot

// Perform iter iterations using the mandelbrot algorithm, and return
// the magnitude of the result
// Strictly speaking, this isn't actually the Mandelbrot set, as we
// return the size of z after iter iterations, rather than the number
// of iteration it takes for z to reach a set value. Nevertheless, it
// still produces nice pictures!
func invMandelbrot(c complex128, iter int) float64 {
	z := complex(0, 0)
	for i := 0; i < iter; i++ {
		z = z*z + c
		if cmplx.Abs(z) > 1000 {
			return 1000
		}
	}
	return cmplx.Abs(z)
}
开发者ID:jamesgarfield,项目名称:go_images,代码行数:16,代码来源:mandelbrot.go

示例11: iterate

// Iterate as per Mandelbrot algo and returns the magnitude
func iterate(c complex128, iter int) float64 {
	z := complex(0, 0)
	for i := 1; i < iter; i++ {
		z = z*z + c
		if cmplx.Abs(z) > 2000 {
			return 2000
		}
	}

	return cmplx.Abs(z)
}
开发者ID:meysampg,项目名称:fractals-in-go,代码行数:12,代码来源:fractal.go

示例12: DistanceLS

// DistanceLS determine the distance between the point and the line segment
func DistanceLS(p, a, b complex128) float64 {
	ab, ba, pa, pb := a-b, b-a, p-a, p-b
	if Dot(ba, pa) < 0 {
		return cmplx.Abs(pa)
	}

	if Dot(ab, pb) < 0 {
		return cmplx.Abs(pb)
	}

	v, z := Cross(ba, 0, pa, 0)
	return math.Sqrt(real(v)*real(v)+imag(v)*imag(v)+z*z) / cmplx.Abs(ba)
}
开发者ID:yukirin,项目名称:algo,代码行数:14,代码来源:geo.go

示例13: colorOf

func colorOf(row int, col int) uint8 {
	c := transform(row, col)
	var z complex128 = c
	for i := 0; i < MAX_ITERS || cmplx.Abs(z) > 2; i += 1 {
		z = z*z + c
	}

	if cmplx.Abs(z) < 2 {
		return uint8(0)
	} else {
		return uint8(255)
	}
}
开发者ID:tlehman,项目名称:mandelbrot,代码行数:13,代码来源:mandelbrot.go

示例14: Cbrt

func Cbrt(x complex128) (z complex128) {
	z = complex128(1)
	lastZ := complex128(0)
	delta := cmplx.Abs(z - lastZ)
	for delta*100000 > 0.00001*100000 {
		//saving last z
		lastZ = z
		//getting new z
		z = z - (((z * z * z) - x) / (3 * (z * z)))
		//figuring out the delta
		delta = cmplx.Abs(z - lastZ)
	}
	return
}
开发者ID:mdewey,项目名称:Learning,代码行数:14,代码来源:NewtonCudeRoot.go

示例15: IsOk

// well-formed superpositions must add up to 100%:
func (p QuantumSuperposition) IsOk() error {
	var sum float64
	for _, v := range p {
		if _v, ok := v.([]interface{}); ok {
			sum += cmplx.Abs(_v[1].(complex128))
		} else {
			sum += cmplx.Abs(v.(complex128))
		}
	}
	if sum != 1 {
		return errors.New("The QuantumSuperposition is not Well Formed")
	}
	return nil
}
开发者ID:sadasant,项目名称:NotAMonad-Go,代码行数:15,代码来源:QuantumSuperposition.go


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