Contents - Index



CURVEFIT1D is a built-in procedure that provides the parameters and statistics resulting from a linear regression curve fit to data provided in array variables.   This procedure provides the same capability as the Curve Fit menu item but it may be more convenient in that the data do not first have to be plotted and the curve fit parameters are returned so that they can be used in following equations.  The CURVEFIT1D procedure has the following format:   


Call CURVEFIT1D(FitType, X[1..n], Y[1..n]: a[1..m], RMS, Bias, R|2, a_stderr[1..m])


FitType is a string constant or string variable that can be any of the following:

'LINEAR'  {­fit is Y[i]=a[0]+a[1]*X[i]}

'POLYNOMIAL1'   or 'POLY1' {­same as linear}

'POLYNOMIAL2'   or 'POLY2' {­fit is Y[i]=a[0]+a[1]*X[i]+a[2]*X[i]^2}

'POLYNOMIAL3'   or 'POLY3' {­fit is Y[i]=a[0]+a[1]*X[i]+a[2]*X[i]^2+a[3]*X[i]^3}

'POLYNOMIAL4'   or 'POLY4' {­fit is Y[i]=a[0]+a[1]*X[i]+a[2]*X[i]^2+a[3]*X[i]^3+a[4]*X[i]^4}

'POLYNOMIAL5'   or 'POLY5' {­fit is Y[i]=a[0]+a[1]*X[i]+a[2]*X[i]^2+a[3]*X[i]^3+a[4]*X[i]^4+a[5]*X[i]^5}

'POLYNOMIAL6'   or 'POLY6' {­fit is Y[i]=a[0]+a[1]*X[i]+a[2]*X[i]^2+a[3]*X[i]^3+a[4]*X[i]^4+a[5]*XY[i]^5+a[6]*X[i]^6}

'EXPONENTIAL'    or 'EXP' {­fit is Y[i]=a[0]*exp(a[1]*X[i])}

'POWER' {­fit is Y[i]=a[0]*X[i]^a[1]}

'LOGARITHMIC'    or 'LOG' {­fit is Y[i]=a[0]+a[1]*ln(X[i])}


X[1..n] is an array of values for the independent variable and Y[1..n] is an array of values for the dependent variables.  n can be a numerical constant or a previously defined EES variable.  The number of data points in the X and Y arrays must be greater than the number of parameters that are being determined and less than 1,000. 


a[1..m] is the array of curve fit parameters returned by the CURVEFIT1D procedures.  Note that m is equal to 2 for all cases except for the POLYNOMIAL fit types in which m is equal to one greater than the polynomial order.  It is not necessary to use array range notation for the curve fit parameters.  For example, a[1..2] can be replaced with a0, a1.


All following outputs are optional.


RMS is root mean square error defined as: sqrt((1/n)*sum[(Y-Y`)^2] where n is the number of data points, and Y` is the estimated value of Y.  


BIAS is the bias error defined as: (1/n)*sum[(Y-Y`)].


R|2 is the correlation coefficient between Y and X


a_stderr[1..m] is the standard error of the curve fit parameters defined as the square root of the estimated variance of the parameter



Example 1:



duplicate i=1,n

x[i]=Lookup('Lookup 1',i,'X')

y[i]=Lookup('Lookup 1,i,'Y')


call curvefit1d('Linear',x[1..n],y[1..n]:a0,a1,rms,bias,R|2,a0_stderr,a1_stderr)



Example 2:

The following example uses a Parametric Table to fits data to polynomials of order 1 through 6.  Note the use of the Concat$ and String$ string functions to generate the different polynomial designations.


n=100 {­n is the number of data points}

F$=concat$('POLY',String$(m)) {­m is other order of the polynomial from the table}

call curvefit1d(F$,X[1..n],Y[1..n]:a[0..m],rms,bias,R|2,a_err[0..m])


duplicate i=1,n


Y[i]=i+2.5*X[i]^2+0.002*X[i]^4+random(0,1)*X[i] {­fake data for the example}

Y`[i]=a[0]+sum(a[j]*X[i]^j,j=1,m) {­predicted value of Y from the polynomial fits}




See also:  Curve fit menu item


Mathematical Functions