curveFitTest.frink

Download or view curveFitTest.frink in plain text format


use curveFit.frink

/** This performs tests on the file curveFit.frink which tries to fit data
    to linear and quadratic curves.
*/


    
// Linear data
data = [ [0, 1], [1, 3], [2, 5] ]
printFit[data]

// Test to verify that units of measure can be fitted correctly.
// THIS EXAMPLE IS ACTUALLY AMAZING!
// It derives the gravitic equation given just 3 points on a curve of
// time and height (and none of those points are forced to be zero, nor are
// the initial height, nor the initial velocity.)  It derives the initial
// velocity at t=0,  the acceleration of gravity, and the initial height at t=0
// given 3 points on the trajectory of an object.
// This is incredibly impressive.
// To generate points, see the Frink solver at:
//   tinyurl.com/2p8pntcd
// This represents the [time, height] data of a projectile being launched from
// an initial height of 2 meters at t=0 s and an initial upward velocity of
// 40 m/s at t = 0 s:
data = [ [1 s, 32.19335 m], [2 s, 42.7734 m], [4.1 s, 1.1502135 m] ]
printFit[data]

// This is the above but with heights rounded to the nearest 0.1 m.
// data = [ [1 s, 32.2 m], [2 s, 42.8 m], [4.1 s, 1.2 m] ]
// printFit[data]


// This demonstrates a purely symbolic result!
symbolicMode[true]
data = [ [x1, y1], [x2, y2], [x3, y3] ]
printFit[data]

printFit[data] :=
{
   println["\n\nFor data: "]
   println[formatTableBoxed[data]]
   println["linear: " + inputForm[linearFit[data]]]
   f = linearFitFunction[data]
   println["\nlinear function: " + inputForm[f]]
   println["\nquadratic: " + inputForm[quadraticFit[data]]]
   f = quadraticFitFunction[data]
   println["\nquadratic function: " + inputForm[f]]
}


Download or view curveFitTest.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 19975 days, 22 hours, 32 minutes ago.