本文整理汇总了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)
}
}
示例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)
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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))
}
示例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))
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
}
示例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
}
示例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
}