Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: fitter.functional - Function Up: fitter - Tool Previous: fitter.getstate - Function


fitter.linear - Function



Package utility
Module fitting
Tool fitter


Solve a linear fitting problem


Synopsis
linear(fnct, x, y, sd, wt, id)


Arguments

fnct in functional to be fitted
    Allowed: a functional
    Default: unset
x in the x coordinate values
    Allowed: vector
y in the ordinate values
    Allowed: vector
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


Returns
bool or fail


Description
linear will make a linear least squares solution for the points through the ordinates at the x values, using the specified fnct. The x can be of any dimension, depending on the number of arguments needed in the functional evaluation. The values should be given in the order: x0[1], x0[2], ..., x1[1], ..., xn[m] if there are n observations, and m arguments. x should be a vector of m*n length; y (the observations) a vector of length n.


Example
- include 'fitting.g'                   # create default fitter
- x := [1:10];                          # some x values
- y := 3*x*x;                           # some y values
- dfit.linear(dfs.poly(2), x, y);       # solve 2nd order polynomial
T
- dfit.solution();
[0 0 3]  
- include 'functionals.g'               # allow functionals
- alin := function() {			# encapsulate some code
z:=dfs.compiled('p0+p1*x0+p2*x1')       # a 2-d functional
x:=[1,2,3,4,5,6]                        # 3 observations
z.setparameters([1,2,3])		# set parameters to get ys
print 'y=', y:=z.f(x)			
dfit.linear(z,x,y)			# fit
print 'linear:', dfit.solution()
z:=dfs.compiled('p0+p1*x0')             # try a 1-d funtional	
x:=[1,3,5]
z.setparameters([1,2])
print 'y=', y:=z.f(x)
dfit.linear(z,x,y)
print 'linear:', dfit.solution()
z:=dfs.compiled('6+p0')			# try a 0-d functional
x:=[]
print 'y=', y:=z.f([1:3])-2
dfit.linear(z,x,y)
print 'linear:', dfit.solution()
return T
}
- alin()
y= [9 19 29] 
linear: [1 2 3] 
y= [3 7 11] 
linear: [1 2] 
y= [4 4 4] 
linear: -2
T





next up previous contents index
Next: fitter.functional - Function Up: fitter - Tool Previous: fitter.getstate - Function   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15