LeastSquaresTest.frink

Download or view LeastSquaresTest.frink in plain text format


/** This tests the least-squares fitting routines in LeastSquares.frink */

use LeastSquares.frink

points = [[1,1], [2,3], [3,3], [4,5], [6,4]]

xvalues = new array
yvalues = new array
for [x,y] = points
{
   xvalues.push[x]
   yvalues.push[y]
}
println["xvalues is $xvalues"]
println["yvalues is $yvalues"]

// Fit the values to a polynomial of the specified degree
ls = LeastSquares.fitDegree[xvalues, yvalues, 2]

println[ls.toMatrix[].formatMatrix[]]
symbolicMode[true]
println[ls.toExpression[]]

println[ls.toArray[]]
println["Residual is " + ls.residual[]]


Download or view LeastSquaresTest.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19967 days, 14 hours, 34 minutes ago.