mirror of
https://github.com/gonum/gonum.git
synced 2025-10-04 14:52:57 +08:00

Changes made in dsp/fourier/internal/fftpack break the formatting used there, so these are reverted. There will be complaints in CI. [git-generate] gofmt -w . go generate gonum.org/v1/gonum/blas go generate gonum.org/v1/gonum/blas/gonum go generate gonum.org/v1/gonum/unit go generate gonum.org/v1/gonum/unit/constant go generate gonum.org/v1/gonum/graph/formats/dot go generate gonum.org/v1/gonum/graph/formats/rdf go generate gonum.org/v1/gonum/stat/card git checkout -- dsp/fourier/internal/fftpack
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
// Copyright ©2017 The Gonum Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package mathext
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
)
|
|
|
|
// TestCompleteKE checks if the Legendre's relation for m=0.0001(0.0001)0.9999
|
|
// is satisfied with accuracy 1e-14.
|
|
func TestCompleteKE(t *testing.T) {
|
|
t.Parallel()
|
|
const tol = 1.0e-14
|
|
|
|
for m := 1; m <= 9999; m++ {
|
|
mf := float64(m) / 10000
|
|
mp := 1 - mf
|
|
K, Kp := CompleteK(mf), CompleteK(mp)
|
|
E, Ep := CompleteE(mf), CompleteE(mp)
|
|
legendre := math.Abs(E*Kp + Ep*K - K*Kp - math.Pi/2)
|
|
if legendre > tol {
|
|
t.Fatalf("legendre > tol: m=%v, legendre=%v, tol=%v", mf, legendre, tol)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestCompleteBD checks if the relations between two associate elliptic integrals B(m), D(m)
|
|
// and more common Legendre's elliptic integrals K(m), E(m) are satisfied with accuracy 1e-14
|
|
// for m=0.0001(0.0001)0.9999.
|
|
//
|
|
// K(m) and E(m) can be computed without cancellation problems as following:
|
|
//
|
|
// K(m) = B(m) + D(m),
|
|
// E(m) = B(m) + (1-m)D(m).
|
|
func TestCompleteBD(t *testing.T) {
|
|
t.Parallel()
|
|
const tol = 1.0e-14
|
|
|
|
for m := 1; m <= 9999; m++ {
|
|
mf := float64(m) / 10000
|
|
B, D := CompleteB(mf), CompleteD(mf)
|
|
K, E := CompleteK(mf), CompleteE(mf)
|
|
difference1 := math.Abs(K - (B + D))
|
|
difference2 := math.Abs(E - (B + (1-mf)*D))
|
|
if difference1 > tol {
|
|
t.Fatalf("difference1 > tol: m=%v, difference1=%v, tol=%v", mf, difference1, tol)
|
|
}
|
|
if difference2 > tol {
|
|
t.Fatalf("difference2 > tol: m=%v, difference2=%v, tol=%v", mf, difference2, tol)
|
|
}
|
|
}
|
|
}
|