本文整理汇总了Golang中github.com/cpmech/gosl/chk.Scalar函数的典型用法代码示例。如果您正苦于以下问题:Golang Scalar函数的具体用法?Golang Scalar怎么用?Golang Scalar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Scalar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_2dinteg02
func Test_2dinteg02(tst *testing.T) {
//verbose()
chk.PrintTitle("2dinteg02. bidimensional integral")
// Γ(1/4, 1)
gamma_1div4_1 := 0.2462555291934987088744974330686081384629028737277219
x := utl.LinSpace(0, 1, 11)
y := utl.LinSpace(0, 1, 11)
m, n := len(x), len(y)
f := la.MatAlloc(m, n)
for i := 0; i < m; i++ {
for j := 0; j < n; j++ {
f[i][j] = 8.0 * math.Exp(-math.Pow(x[i], 2)-math.Pow(y[j], 4))
}
}
dx, dy := x[1]-x[0], y[1]-y[0]
Vt := Trapz2D(dx, dy, f)
Vs := Simps2D(dx, dy, f)
Vc := math.Sqrt(math.Pi) * math.Erf(1) * (math.Gamma(1.0/4.0) - gamma_1div4_1)
io.Pforan("Vt = %v\n", Vt)
io.Pforan("Vs = %v\n", Vs)
io.Pfgreen("Vc = %v\n", Vc)
chk.Scalar(tst, "Vt", 0.0114830435645548, Vt, Vc)
chk.Scalar(tst, "Vs", 1e-4, Vs, Vc)
}
示例2: Test_munkres04
func Test_munkres04(tst *testing.T) {
//verbose()
chk.PrintTitle("munkres04. row and column matrices")
C := [][]float64{
{1.0},
{2.0},
{0.5},
{3.0},
{4.0},
}
var mnk Munkres
mnk.Init(len(C), len(C[0]))
mnk.SetCostMatrix(C)
mnk.Run()
io.Pforan("links = %v\n", mnk.Links)
io.Pforan("cost = %v (13938)\n", mnk.Cost)
chk.Ints(tst, "links", mnk.Links, []int{-1, -1, 0, -1, -1})
chk.Scalar(tst, "cost", 1e-17, mnk.Cost, 0.5)
C = [][]float64{
{1.0, 2.0, 0.5, 3.0, 4.0},
}
mnk.Init(len(C), len(C[0]))
mnk.SetCostMatrix(C)
mnk.Run()
io.Pforan("links = %v\n", mnk.Links)
io.Pforan("cost = %v (13938)\n", mnk.Cost)
chk.Ints(tst, "links", mnk.Links, []int{2})
chk.Scalar(tst, "cost", 1e-17, mnk.Cost, 0.5)
}
示例3: Test_quad01
func Test_quad01(tst *testing.T) {
//verbose()
chk.PrintTitle("quad01")
y := func(x float64) float64 {
return math.Sqrt(1.0 + math.Pow(math.Sin(x), 3.0))
}
var err error
Acor := 1.08268158558
// trapezoidal rule
var T Quadrature
T = new(Trap)
T.Init(y, 0, 1, 1e-11)
A, err := T.Integrate()
if err != nil {
io.Pforan(err.Error())
}
io.Pforan("A = %v\n", A)
chk.Scalar(tst, "A", 1e-11, A, Acor)
// Simpson's rule
var S Quadrature
S = new(Simp)
S.Init(y, 0, 1, 1e-11)
A, err = S.Integrate()
if err != nil {
io.Pforan(err.Error())
}
io.Pforan("A = %v\n", A)
chk.Scalar(tst, "A", 1e-11, A, Acor)
}
示例4: Test_mylab08
func Test_mylab08(tst *testing.T) {
//verbose()
chk.PrintTitle("mylab08. dot and cross products")
u := []float64{3, -3, 1}
v := []float64{4, 9, 2}
w := make([]float64, 3)
s := Dot3d(u, v)
Cross3d(w, u, v) // w := u cross v
chk.Scalar(tst, "s = u dot v", 1e-17, s, -13)
chk.Vector(tst, "w = u cross v", 1e-17, w, []float64{-15, -2, 39})
u = []float64{3, -3, 1}
v = []float64{-12, 12, -4}
s = Dot3d(u, v)
Cross3d(w, u, v) // w := u cross v
chk.Scalar(tst, "s = u dot v", 1e-17, s, -76)
chk.Vector(tst, "w = u cross v", 1e-17, w, []float64{0, 0, 0})
u = []float64{3, 2, -2}
v = []float64{1, 0, -5}
s = Dot3d(u, v)
Cross3d(w, u, v) // w := u cross v
chk.Scalar(tst, "s = u dot v", 1e-17, s, 13)
chk.Vector(tst, "w = u cross v", 1e-17, w, []float64{-10, 13, -2})
}
示例5: Test_invs07
func Test_invs07(tst *testing.T) {
//verbose()
chk.PrintTitle("invs07")
smp_a, smp_b, smp_β, smp_ϵ := -1.0, 0.0, 1.0, 1e-3
σ := []float64{-1, -1, 0, 0}
pcam, qcam, _ := M_pqw(σ)
poct, qoct := pcam*SQ3, qcam*SQ2by3
N := make([]float64, 3)
n := make([]float64, 3)
m := SmpDirector(N, σ, smp_a, smp_b, smp_β, smp_ϵ)
SmpUnitDirector(n, m, N)
psmp1, qsmp1, err := GenInvs(σ, n, smp_a)
if err != nil {
chk.Panic("M_GenInvs failed:\n%v", err)
}
psmp2, qsmp2, err := M_pq_smp(σ, smp_a, smp_b, smp_β, smp_ϵ)
if err != nil {
chk.Panic("M_pq_smp failed:\n%v", err)
}
io.Pforan("pcam, qcam = %v, %v\n", pcam, qcam)
io.Pforan("poct, qoct = %v, %v\n", poct, qoct)
io.Pforan("psmp1, qsmp1 = %v, %v\n", psmp1, qsmp1)
io.Pforan("psmp2, qsmp2 = %v, %v\n", psmp2, qsmp2)
chk.Scalar(tst, "p", 1e-15, psmp1, psmp2)
chk.Scalar(tst, "q", 1e-15, qsmp1, qsmp2)
}
示例6: Test_beam01b
func Test_beam01b(tst *testing.T) {
//verbose()
chk.PrintTitle("beam01b. simply supported")
// start simulation
analysis := NewFEM("data/beam01.sim", "", true, true, false, false, chk.Verbose, 0)
// run simulation
err := analysis.Run()
if err != nil {
tst.Errorf("Run failed:\n%v", err)
return
}
// check
dom := analysis.Domains[0]
ele := dom.Elems[0].(*Beam)
_, M := ele.CalcVandM(dom.Sol, 0.5, 1)
qn, L := 15.0, 1.0
Mcentre := qn * L * L / 8.0
io.Pforan("M = %v (%v)\n", M, Mcentre)
chk.Scalar(tst, "M @ centre", 1e-17, M[0], Mcentre)
// check moment using OutIpsData
idx_centre := 5 // considering 11 stations
dat := ele.OutIpsData()
res := dat[idx_centre].Calc(dom.Sol)
io.Pfcyan("M @ centre (OutIpsData) = %v\n", res["M"])
chk.Scalar(tst, "M @ centre (OutIpsData)", 1e-17, res["M"], Mcentre)
}
示例7: TestMyLab03b
func TestMyLab03b(tst *testing.T) {
//verbose()
chk.PrintTitle("mylab03b")
a := []int{1, 2, 3, -1, -2, 0, 8, -3}
b := IntFilter(a, func(i int) bool {
if a[i] < 0 {
return true
}
return false
})
c := IntNegOut(a)
io.Pf("a = %v\n", a)
io.Pf("b = %v\n", b)
io.Pf("c = %v\n", c)
chk.Ints(tst, "b", b, []int{1, 2, 3, 0, 8})
chk.Ints(tst, "c", c, []int{1, 2, 3, 0, 8})
A := []float64{1, 2, 3, -1, -2, 0, 8, -3}
s := DblSum(A)
mi, ma := DblMinMax(A)
io.Pf("A = %v\n", A)
io.Pf("sum(A) = %v\n", s)
io.Pf("min(A) = %v\n", mi)
io.Pf("max(A) = %v\n", ma)
chk.Scalar(tst, "sum(A)", 1e-17, s, 8)
chk.Scalar(tst, "min(A)", 1e-17, mi, -3)
chk.Scalar(tst, "max(A)", 1e-17, ma, 8)
}
示例8: Test_prms02
func Test_prms02(tst *testing.T) {
//verbose()
chk.PrintTitle("prms02")
var prms Prms
prms = []*Prm{
&Prm{N: "klx", V: 1.0},
&Prm{N: "kly", V: 2.0},
&Prm{N: "klz", V: 3.0},
}
io.Pforan("%v\n", prms)
var klx, kly, klz float64
err_msg := prms.ConnectSet([]*float64{&klx, &kly, &klz}, []string{"klx", "kly", "klz"}, "Test_prms02")
if err_msg != "" {
tst.Error("connect set failed: %v\n", err_msg)
return
}
chk.Scalar(tst, "klx", 1e-15, klx, 1.0)
chk.Scalar(tst, "kly", 1e-15, kly, 2.0)
chk.Scalar(tst, "klz", 1e-15, klz, 3.0)
prms[1].Set(2.2)
chk.Scalar(tst, "kly", 1e-15, kly, 2.2)
}
示例9: Test_ind01
func Test_ind01(tst *testing.T) {
//verbose()
chk.PrintTitle("ind01. representation and copying")
rnd.Init(0)
nbases := 3
A := get_individual(0, nbases)
B := A.GetCopy()
chk.Scalar(tst, "ova0", 1e-17, B.Ovas[0], 123)
chk.Scalar(tst, "ova1", 1e-17, B.Ovas[1], 345)
chk.Scalar(tst, "oor0", 1e-17, B.Oors[0], 10)
chk.Scalar(tst, "oor1", 1e-17, B.Oors[1], 20)
chk.Scalar(tst, "oor2", 1e-17, B.Oors[2], 30)
fmts := map[string][]string{"int": {" %d"}, "flt": {" %.1f"}, "str": {" %q"}, "key": {" %x"}, "byt": {" %q"}, "fun": {" %q"}}
oA := A.Output(fmts, false)
oB := B.Output(fmts, false)
io.Pfyel("\n%v\n", oA)
io.Pfyel("%v\n\n", oB)
chk.String(tst, oA, " 1 20 300 4.4 5.5 666.0 \"abc\" \"b\" \"c\" 53 47 41 \"ABC\" \"DEF\" \"GHI\" \"f0\" \"f1\" \"f2\"")
chk.String(tst, oB, " 1 20 300 4.4 5.5 666.0 \"abc\" \"b\" \"c\" 53 47 41 \"ABC\" \"DEF\" \"GHI\" \"f0\" \"f1\" \"f2\"")
A.SetFloat(1, 33)
A.SetFloat(2, 88)
oA = A.Output(fmts, false)
io.Pfyel("\n%v\n", oA)
chk.String(tst, oA, " 1 20 300 4.4 33.0 88.0 \"abc\" \"b\" \"c\" 53 47 41 \"ABC\" \"DEF\" \"GHI\" \"f0\" \"f1\" \"f2\"")
}
示例10: Test_matinvSmall01
func Test_matinvSmall01(tst *testing.T) {
//verbose()
chk.PrintTitle("matinvSmall01")
noise := 0.0
tol := 1.0e-16
// 1 x 1 matrix
res := MatAlloc(1, 1)
det, err := MatInv(res, [][]float64{{2.0}}, tol)
if err != nil {
chk.Panic("%v", err.Error())
}
chk.Scalar(tst, "1 x 1 matrix: det ", tol, det, 2.0)
chk.Matrix(tst, "1 x 1 matrix: ", tol, res, [][]float64{{0.5}})
// matrix: inverse
A := [][]float64{{1.0, 2.0}, {3.0, 2.0}}
Aicorr := [][]float64{{-0.5, 0.5}, {0.75, -0.25 + noise}}
Ai := MatAlloc(2, 2)
detA, err := MatInv(Ai, A, tol)
if err != nil {
chk.Panic("%v", err.Error())
}
chk.Scalar(tst, "matrix: inv (det) ", tol, detA, -4.0+noise)
chk.Matrix(tst, "matrix: inv (A) ", tol, Ai, Aicorr)
// using MatInvG
Ai_ := MatAlloc(2, 2)
err = MatInvG(Ai_, A, tol)
if err != nil {
chk.Panic("%v", err.Error())
}
chk.Matrix(tst, "matrix: inv with MatInvG", tol, Ai_, Aicorr)
// another test
B := [][]float64{{9.0, 3.0, 5.0}, {-6.0, -9.0, 7.0}, {-1.0, -8.0, 1.0}}
Bicorr := [][]float64{
{7.642276422764227e-02, -6.991869918699187e-02, 1.073170731707317e-01},
{-1.626016260162601e-03, 2.276422764227642e-02, -1.512195121951219e-01},
{6.341463414634146e-02, 1.121951219512195e-01, -1.024390243902439e-01 + noise},
}
Bi := MatAlloc(3, 3)
detB, err := MatInv(Bi, B, tol)
if err != nil {
chk.Panic("%v", err.Error())
}
chk.Scalar(tst, "matrix: det ", tol, detB, 615.0+noise)
chk.Matrix(tst, "matrix: inv ", tol, Bi, Bicorr)
// using MatInvG
Bi_ := MatAlloc(3, 3)
err = MatInvG(Bi_, B, tol)
if err != nil {
chk.Panic("%v", err.Error())
}
chk.Matrix(tst, "matrix: inv with MatInvG", tol, Bi_, Bicorr)
}
示例11: Test_ind02
func Test_ind02(tst *testing.T) {
//verbose()
chk.PrintTitle("ind02. copy into")
rnd.Init(0)
nbases := 1
A := get_individual(0, nbases)
B := get_individual(1, nbases)
fmts := map[string][]string{
"int": {"%2d", "%4d", "%5d"}, // ints
"flt": {"%6g", "%6g", "%5g"}, // floats
"str": {"%4s", "%2s", "%2s"}, // strings
"key": {"%3x", "%3x", "%3x"}, // keys
"byt": {"%4s", "%4s", "%4s"}, // bytes
"fun": {"%3s", "%3s", "%3s"}, // funcs
}
io.Pfpink("A = %v\n", A.Output(fmts, false))
io.Pfcyan("B = %v\n", B.Output(fmts, false))
var ops OpsData
ops.SetDefault()
ops.Pc = 1.0
ops.Cuts = []int{1, 2}
ops.Xrange = [][]float64{{0, 1}, {-20, 20}, {-300, 300}}
a := A.GetCopy()
b := A.GetCopy()
IndCrossover(a, b, A, B, 0, &ops)
io.Pforan("a = %v\n", a.Output(fmts, false))
io.Pfblue2("b = %v\n", b.Output(fmts, false))
chk.Ints(tst, "a.Ints ", a.Ints, []int{1, -20, 300})
chk.Ints(tst, "b.Ints ", b.Ints, []int{-1, 20, -300})
chk.Strings(tst, "a.Strings", a.Strings, []string{"abc", "Y", "c"})
chk.Strings(tst, "b.Strings", b.Strings, []string{"X", "b", "Z"})
// TODO: add other tests here
io.Pf("\n")
x := get_individual(0, nbases)
x.Ovas = []float64{0, 0}
x.Oors = []float64{0, 0, 0}
io.Pfblue2("x = %v\n", x.Output(fmts, false))
B.CopyInto(x)
chk.Scalar(tst, "ova0", 1e-17, x.Ovas[0], 200)
chk.Scalar(tst, "ova1", 1e-17, x.Ovas[1], 100)
chk.Scalar(tst, "oor0", 1e-17, x.Oors[0], 15)
chk.Scalar(tst, "oor1", 1e-17, x.Oors[1], 25)
chk.Scalar(tst, "oor2", 1e-17, x.Oors[2], 35)
io.Pforan("x = %v\n", x.Output(fmts, false))
chk.String(tst, x.Output(fmts, false), B.Output(fmts, false))
}
示例12: Test_fun05
func Test_fun05(tst *testing.T) {
//verbose()
chk.PrintTitle("fun05. zero and one")
io.Pforan("Zero(666,nil) = %v\n", Zero.F(666, nil))
io.Pforan("One(666,nil) = %v\n", One.F(666, nil))
chk.Scalar(tst, "zero", 1e-17, Zero.F(666, nil), 0)
chk.Scalar(tst, "one ", 1e-17, One.F(666, nil), 1)
}
示例13: check_constants
func check_constants(tst *testing.T, E, ν, Kcor, Gcor, lcor float64) {
K, G := Calc_K_from_Enu(E, ν), Calc_G_from_Enu(E, ν)
l := Calc_l_from_Enu(E, ν)
io.Pf("E = %v\n", E)
io.Pf("ν = %v\n", ν)
io.Pf("K = %v\n", K)
io.Pf("G = %v\n", G)
io.Pf("l = %v\n", l)
chk.Scalar(tst, "KfromEν", 1e-17, K, Kcor)
chk.Scalar(tst, "GfromEν", 1e-17, G, Gcor)
chk.Scalar(tst, "lfromEν", 1e-17, l, lcor)
EfromKG, νfromKG := Calc_E_from_KG(K, G), Calc_nu_from_KG(K, G)
chk.Scalar(tst, "EfromKG", 1e-17, EfromKG, E)
chk.Scalar(tst, "νfromKG", 1e-17, νfromKG, ν)
EfromlG, νfromlG := Calc_E_from_lG(l, G), Calc_nu_from_lG(l, G)
chk.Scalar(tst, "EfromlG", 1e-17, EfromlG, E)
chk.Scalar(tst, "νfromlG", 1e-17, νfromlG, ν)
EfromKν, GfromKν := Calc_E_from_Knu(K, ν), Calc_G_from_Knu(K, ν)
chk.Scalar(tst, "EfromKν", 1e-17, EfromKν, E)
chk.Scalar(tst, "GfromKν", 1e-17, GfromKν, G)
}
示例14: Test_gumbel_03
func Test_gumbel_03(tst *testing.T) {
//verbose()
chk.PrintTitle("dist_gumbel_03")
var dist DistGumbel
dist.Init(&VarData{M: 61.3, S: 7.52}) // from Haldar & Mahadevan page 90
io.Pforan("dist = %+#v\n", dist)
chk.Scalar(tst, "u", 0.00011, dist.U, 57.9157)
chk.Scalar(tst, "β", 1e-4, dist.B, 1.0/0.17055)
}
示例15: Test_cubiceq02
func Test_cubiceq02(tst *testing.T) {
//verbose()
chk.PrintTitle("cubiceq02. y(x) = x³ + x²")
a, b, c := 1.0, 0.0, 0.0
x1, x2, x3, nx := EqCubicSolveReal(a, b, c)
io.Pforan("\na=%v b=%v c=%v\n", a, b, c)
io.Pfcyan("nx=%v\n", nx)
io.Pfcyan("x1=%v x2=%v x3=%v\n", x1, x2, x3)
chk.IntAssert(nx, 2)
chk.Scalar(tst, "x1", 1e-17, x1, -1)
chk.Scalar(tst, "x2", 1e-17, x2, 0)
}