本文整理汇总了Golang中github.com/cpmech/gosl/chk.Scalar函数的典型用法代码示例。如果您正苦于以下问题:Golang Scalar函数的具体用法?Golang Scalar怎么用?Golang Scalar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Scalar函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:28,代码来源:t_integ_test.go
示例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)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:33,代码来源:t_munkres_test.go
示例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)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:33,代码来源:t_quadrature_test.go
示例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})
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:27,代码来源:t_mylab_test.go
示例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)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:32,代码来源:t_invariants_test.go
示例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)
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:31,代码来源:t_beams_test.go
示例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)
}
开发者ID:PatrickSchm,项目名称:gosl,代码行数:30,代码来源:t_mylab_test.go
示例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)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:27,代码来源:t_prms_test.go
示例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\"")
}
开发者ID:postfix,项目名称:goga-1,代码行数:31,代码来源:t_individual_test.go
示例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)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:59,代码来源:t_matinv_test.go
示例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))
}
开发者ID:postfix,项目名称:goga-1,代码行数:57,代码来源:t_individual_test.go
示例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)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:10,代码来源:t_fun_test.go
示例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)
}
开发者ID:PatrickSchm,项目名称:gofem,代码行数:27,代码来源:t_elasticity_test.go
示例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)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:11,代码来源:t_dist_gumbel_test.go
示例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)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:14,代码来源:t_equations_test.go
示例16: Test_cubiceq01
func Test_cubiceq01(tst *testing.T) {
//verbose()
chk.PrintTitle("cubiceq01. y(x) = x³ - 3x² - 144x + 432")
a, b, c := -3.0, -144.0, 432.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, 3)
chk.Scalar(tst, "x1", 1e-17, x1, -12)
chk.Scalar(tst, "x2", 1e-17, x2, 12)
chk.Scalar(tst, "x3", 1e-14, x3, 3)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:15,代码来源:t_equations_test.go
示例17: Test_simplechromo01
func Test_simplechromo01(tst *testing.T) {
//verbose()
chk.PrintTitle("simplechromo01")
rnd.Init(0)
nbases := 2
for i := 0; i < 10; i++ {
chromo := SimpleChromo([]float64{1, 10, 100}, nbases)
io.Pforan("chromo = %v\n", chromo)
chk.IntAssert(len(chromo), 3*nbases)
chk.Scalar(tst, "gene0", 1e-14, chromo[0]+chromo[1], 1)
chk.Scalar(tst, "gene1", 1e-14, chromo[2]+chromo[3], 10)
chk.Scalar(tst, "gene2", 1e-13, chromo[4]+chromo[5], 100)
}
}
开发者ID:postfix,项目名称:goga-1,代码行数:16,代码来源:t_operators_test.go
示例18: Test_phi03
func Test_phi03(tst *testing.T) {
// verbose()
chk.PrintTitle("phi03 - Reinitialisation")
// run simulation
analysis := NewFEM("data/phi03.sim", "", true, false, false, false, chk.Verbose, 0)
// run simulation
err := analysis.Run()
if err != nil {
tst.Errorf("Run failed:\n%v", err)
return
}
// domain
dom := analysis.Domains[0]
eq := []int{
0, 20, 54,
}
node := []int{
0, 10, 27,
}
// check results
for i, v := range eq {
// chk.PrintTitle(io.Sf("%25.10e%25.10e", dom.Sol.Y[v], dom.Msh.Verts[node[i]].C[0]))
chk.Scalar(tst, "h @ nod "+string(i), 5e-2, dom.Sol.Y[v], dom.Msh.Verts[node[i]].C[0])
}
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:29,代码来源:t_phi_test.go
示例19: Test_msh01
func Test_msh01(tst *testing.T) {
chk.PrintTitle("msh01")
msh := ReadMsh("data", "bh16.msh")
if msh == nil {
tst.Errorf("test failed\n")
return
}
io.Pforan("%v\n", msh)
io.Pfcyan("lims = [%g, %g, %g, %g, %g, %g]\n", msh.Xmin, msh.Xmax, msh.Ymin, msh.Ymax, msh.Zmin, msh.Zmax)
chk.Scalar(tst, "xmin", 1e-17, msh.Xmin, 10)
chk.Scalar(tst, "xmax", 1e-17, msh.Xmax, 14)
chk.Scalar(tst, "ymin", 1e-17, msh.Ymin, -1)
chk.Scalar(tst, "ymax", 1e-17, msh.Ymax, 1)
}
开发者ID:PatrickSchm,项目名称:gofem,代码行数:16,代码来源:t_read_test.go
示例20: Test_brent03
func Test_brent03(tst *testing.T) {
//verbose()
chk.PrintTitle("brent03. minimum finding")
ffcn := func(x float64) (res float64, err error) {
return x*x*x - 2.0*x - 5.0, nil
}
var o Brent
o.Init(ffcn)
xa, xb := 0.0, 1.0
x, err := o.Min(xa, xb, false)
if err != nil {
chk.Panic("%v", err)
}
y, err := ffcn(x)
if err != nil {
chk.Panic("%v", err)
}
xcor := math.Sqrt(2.0 / 3.0)
io.Pforan("x = %v (correct=%g)\n", x, xcor)
io.Pforan("f(x) = %v\n", y)
io.Pforan("nfeval = %v\n", o.NFeval)
io.Pforan("nit = %v\n", o.It)
//save := true
save := false
PlotYxe(ffcn, "results", "brent03.png", x, -1, 3, 101, "Brent", "'b-'", save, false, nil)
chk.Scalar(tst, "xcorrect", 1e-8, x, xcor)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:31,代码来源:t_brent_test.go
注:本文中的github.com/cpmech/gosl/chk.Scalar函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论