Polynomial regression: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: Replaced IupPlot with IupGraph, added online link) |
|||
Line 987: | Line 987: | ||
import ( |
import ( |
||
"fmt" |
|||
"log" |
|||
"gonum.org/v1/gonum/mat" |
|||
"github.com/gonum/matrix/mat64" |
|||
) |
) |
||
⚫ | |||
var ( |
var ( |
||
⚫ | |||
x = []float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} |
|||
⚫ | |||
degree = 3 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
c = mat.NewDense(degree, 1, nil) |
|||
⚫ | |||
⚫ | |||
var qr mat.QR |
|||
qr.Factorize(a) |
|||
const trans = false |
|||
err := qr.SolveTo(c, trans, b) |
|||
if err != nil { |
|||
fmt.Println(err) |
|||
log.Fatalf("could not solve QR: %+v", err) |
|||
} else { |
|||
} |
|||
fmt.Printf("%.3f\n", mat.Formatted(c)) |
|||
} |
|||
} |
} |
||
func Vandermonde(a []float64, |
func Vandermonde(a []float64, d int) *mat.Dense { |
||
x := mat.NewDense(len(a), d, nil) |
|||
for i := range a { |
|||
for j, p := 0, 1.0; j < d; j, p = j+1, p*a[i] { |
|||
x.Set(i, j, p) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return x |
|||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |