go-hep.org/x/hep@v0.38.1/fit/poly_example_test.go (about)

     1  // Copyright ©2025 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package fit_test
     6  
     7  import (
     8  	"fmt"
     9  	"log"
    10  
    11  	"go-hep.org/x/hep/fit"
    12  )
    13  
    14  func ExamplePoly() {
    15  	var (
    16  		xs      = []float64{0.0, 1.0, 2.0, 3.0, +4.0, +5.0}
    17  		ys      = []float64{0.0, 0.8, 0.9, 0.1, -0.8, -1.0}
    18  		degree  = 3
    19  		zs, err = fit.Poly(xs, ys, degree)
    20  	)
    21  
    22  	if err != nil {
    23  		log.Fatalf("could not fit polynomial: %v", err)
    24  	}
    25  
    26  	fmt.Printf("z = %+.5f\n", zs)
    27  	// Output:
    28  	// z = [+0.08704 -0.81349 +1.69312 -0.03968]
    29  }