拟合GPS位置
This commit is contained in:
29
pkg/utils/interp_lagrange_test.go
Normal file
29
pkg/utils/interp_lagrange_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInterpLagrange(t *testing.T) {
|
||||
x := []float64{0, 1, 2, 3, 4}
|
||||
y := []float64{0, 1, 4, 9, 16}
|
||||
|
||||
interp := &LagrangeInterpolator{}
|
||||
if err := interp.Fit(x, y); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
fmt.Println("x = 2.5, y =", interp.Predict(2.5))
|
||||
fmt.Println("x = 5.5, y =", interp.Predict(5.5))
|
||||
fmt.Println("x = 2, y =", interp.Predict(2.0))
|
||||
|
||||
p := &PolynomialInterpolator{}
|
||||
if err := p.Fit(x, y); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
fmt.Println("x = 2.5, y =", p.Predict(2.5))
|
||||
fmt.Println("x = 5.5, y =", p.Predict(5.5))
|
||||
fmt.Println("x = 2, y =", p.Predict(2.0))
|
||||
}
|
||||
Reference in New Issue
Block a user