Files
goNum/MaxAbs.go
Black Ghost 96fccdb6ef update comments
update comments in all of files in convenient to generate package information using `godoc` command or give tips in LiteIDE editor when the cursor keeps resting on a function or method.
2019-03-01 10:10:32 +08:00

55 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Max
/*
------------------------------------------------------
作者 : Black Ghost
日期 : 2018-11-19
版本 : 0.0.0
------------------------------------------------------
向量第一个绝对值最大值及其位置
------------------------------------------------------
输入 :
a a 被处理向量
输出 :
sol 解值
ii 第一个绝对值最大值位置
err 解出标志false-未解出或达到步数上限;
true-全部解出
------------------------------------------------------
*/
package goNum
import (
"math"
)
// MaxAbs 向量第一个绝对值最大值及其位置
func MaxAbs(a []float64) (float64, int, bool) {
/*
向量第一个绝对值最大值及其位置
输入 :
a a 被处理向量
输出 :
sol 解值
ii 第一个最大值位置
err 解出标志false-未解出或达到步数上限;
true-全部解出
*/
var sol float64
var ii int
var err bool = false
n := len(a)
ii = 0
sol = a[ii]
for i := 1; i < n; i++ {
if math.Abs(sol) < math.Abs(a[i]) {
ii = i
sol = a[i]
}
}
err = true
return sol, ii, err
}