Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
Package | utility | |
Module | fitting | |
Tool | fitter |
n | in | the order of the polynomial to solve for | |
Allowed: | integer | ||
x | in | the parameter for the polynomial calculations | |
Allowed: | one or more real or complex values | ||
y | in | observed values of the condition equations | |
Allowed: | N x m values | ||
sd | in | standard deviation of equations | |
Allowed: | one or more values used cyclically | ||
Default: | unset | ||
wt | in | an optional alternate for sd | |
Allowed: | one or more values used cyclically | ||
Default: | 1 | ||
id | in | the id of a sub-tool | |
Allowed: | fitter id | ||
Default: | 0 |
The method expects that the properties of the fitter to be used have been initialized or set (like the number of simultaneous solutions m; the type; factors). The main reason is to limit the number of parameters on the one hand, and on the other hand not to depend on the actual array structure in Glish to get the variables and type.
- include 'fitting.g' - fit := fitter(); # a fitter for real unknowns - x:=[1:10] # we have values at 10 'x' values - y:=2+0.5*x-0.1*x^2 # which are 2 +0.5x -0.1x^2 - fit.fitpoly(3,x,y) # fit a 3-degree polynomial T - print fit.solution(), fit.error() # show solution and their errors [2 0.5 -0.1 -6.21725e-14] [0 0 0 0]
Note the big problem with polynomial fitting if you have relatively large x values: the internal precision of computers start to play a role. In general it is worth the effort to normalize x between -1 and 1. To aid in most standard cases, a function fitspoly has been provided.