Poly <n>
Description Calculates the best fit nth order polynomial, plots the result and prints the coefficients and rms error.
  Defines the best fit as having the smallest rms error. The polynomial coefficients are output along with the error. The polynomial is then plotted.
Hot Key  none
Script previous = current
poly current <n>
print rms(previous-current)

Open scope and paste this script into the command window.
Then press <Ctrl + R> to plot a square wave

Select the Calculator menu "Functions//Filters/Poly 7 to check it out.

numpoints = 500
time = (vector(numpoints)/(numpoints-1)*1m)
newplot pulseplot time
setplot pulseplot
setunits time sec
y = 2*pulse(500u) - 1
plot y