Download or view LeastSquaresFitAlc.frink in plain text format
/** This tests the least-squares fitting routines in LeastSquares.frink */
use LeastSquares.frink
use Grid.frink
allpoints = new array
for line= lines["file:/home/eliasen/prog/webroot/images/alc.txt"]
{
points = split[%r/\s+/, line]
// This gives alcohol percentage by volume to density.
// Remove the reverse to give density to percentage by volume. For example:
//allpoints.push[mul[eval[points], [g/cm^3, percent]]]
allpoints.push[reverse[eval[points]]]
}
println["allpoints is $allpoints"]
// Fit the values to a polynomial of the specified degree
[bestf, bestr] = LeastSquares.fitDegreePiecewise3[allpoints, 3]
//println[ls.toMatrix[].formatMatrix[]]
//symbolicMode[true]
//println[ls.toExpression[]]
println[inputForm[bestf]]
println["r-value is $bestr"]
g = new graphics
p = new polyline
dummyX =!= dummyX
dummyY =!= dummyY
for [density, abv] = sort[allpoints, byColumn[0]]
{
g.fillEllipseCenter[abv dummyX,-density dummyY, 0.3 dummyX, 0.001 dummyY]
p.addPoint[bestf[density] dummyX, -density dummyY]
}
g.color[0,0,1]
g.add[p]
grid = new Grid
grid.setUnits[dummyX, -dummyY]
grid.auto[g]
g.add[grid.getGrid[]]
g.show[]
Download or view LeastSquaresFitAlc.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, eliasen@mindspring.com