Files
mopac-pdf/vendor/github.com/wcharczuk/go-chart/v2/matrix/regression.go
T
mrcharles 10e930e46d mopac-pdf v0: markdown to beautiful PDFs via digest-pinned typst
Go CLI that turns the markdown currency of this stack (Redmine notes,
Discourse posts, briefing output) into typeset PDFs: two embedded typst
templates (report with title page/TOC/headers, dense brief), front-matter
(title/subtitle/author/date/classification/template), GFM tables, and
bar charts rendered in pure Go (go-chart) from fenced chart data blocks.
Engine is a prebuilt typst 0.15.1 container pinned by digest and run
--network none; PDF bytes to stdout or -o. Exit codes 0/1/2.

All dev in docker (dev.sh/Makefile); unit tests + golden typst fixtures
plus a host-side smoke against the real engine container.

Generated with Crush

Assisted-by: Crush:glm-5.2
2026-08-29 05:44:24 -05:00

46 lines
894 B
Go

package matrix
import "errors"
var (
// ErrPolyRegArraysSameLength is a common error.
ErrPolyRegArraysSameLength = errors.New("polynomial array inputs must be the same length")
)
// Poly returns the polynomial regress of a given degree over the given values.
func Poly(xvalues, yvalues []float64, degree int) ([]float64, error) {
if len(xvalues) != len(yvalues) {
return nil, ErrPolyRegArraysSameLength
}
m := len(yvalues)
n := degree + 1
y := New(m, 1, yvalues...)
x := Zero(m, n)
for i := 0; i < m; i++ {
ip := float64(1)
for j := 0; j < n; j++ {
x.Set(i, j, ip)
ip *= xvalues[i]
}
}
q, r := x.QR()
qty, err := q.Transpose().Times(y)
if err != nil {
return nil, err
}
c := make([]float64, n)
for i := n - 1; i >= 0; i-- {
c[i] = qty.Get(i, 0)
for j := i + 1; j < n; j++ {
c[i] -= c[j] * r.Get(i, j)
}
c[i] /= r.Get(i, i)
}
return c, nil
}