home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / lsqrft15.zip / fit.hlp < prev    next >
Text File  |  1994-02-11  |  32KB  |  869 lines

  1. INSTALLATION
  2.  
  3.  Unzip the zip file in a suitable directory.  Move
  4.  fit2.exe somewhere in your path.  If you want the online
  5.  help to work, set the environment variable "fithelp" to
  6.  point to the file fit.hlp.  For example:
  7.  
  8.  set fithelp=d:\docs\fit.hlp
  9.  
  10.  Under Unix, you should use setenv, something like:
  11.  
  12.  setenv FITHELP /u/docs/fit.hlp
  13.  
  14.  Adding the line to your config.sys (under OS/2) or 
  15.  autoexec.bat (under DOS) or .cshrc would keep you from 
  16.  having to type it in every time you reboot or login.  
  17.  The gnuplot.exe program should be somewhere in your path.
  18.  The fit program requires you have gplt33b2.zip or later
  19.  under OS/2.  Earlier versions work under Unix. This file 
  20.  is available from ftp.cdrom.com and includes complete 
  21.  documentation.  As of 10/1/93 the most recent version of
  22.  gnuplot is 3.5.
  23.  
  24.  Under OS/2 2.x,  you should move all the *.DLL files to
  25.  a directory in your LIBPATH.
  26.  
  27.  For use on platforms other than OS/2 2.x or DOS, you will
  28.  have to compile. Have a look at the makefile and make it 
  29.  suitable for your compiler. You might want to make the 
  30.  executable fit2 instead of fit2.exe. You should also use 
  31.  the compiler option -DUNIX (instead of -DOS2), or whatever
  32.  option will define UNIX for your compiler.  I recommend
  33.  using the GCC compiler for the most painless compilation
  34.  on any UNIX platform, but other compilers have been shown
  35.  to work as well.  You might get some warnings.
  36.  
  37.  Under DOS, you should use the DJGPP port of GCC.  Borland 
  38.  C++ will not work.  To run in a DOS box under Windows, you
  39.  must use version 1.10 or higher of DJGPP.  Specify the 
  40.  -DDOS option when you compile under DOS.  Plotting is 
  41.  disabled in the DOS version.  You will have to write the 
  42.  fit to a temporary file, and plot with the plotting 
  43.  package of your choice.  DJGPP is not the most usable DOS 
  44.  compiler, but it is free, has a 32 bit DOS extender, and 
  45.  is good for porting UNIX programs.  Consult the DJGPP 
  46.  documentation and the *.msdos.programmer newsgroups for 
  47.  more info on DJGPP.  You must have the file go32.exe in 
  48.  your path for the DOS version to work.
  49.  
  50.  -DUNIX affects the command used to open gnuplot.  Gnuplot
  51.  writes some error messages to stderr and some of these 
  52.  make it to the screen.  If -DUNIX is specified, stderr is 
  53.  redirected to the file gnuout.  If you want to see the 
  54.  error messages, do not use -DUNIX.  Additionally, some 
  55.  gnuplot terminal types require stderr to go to the screen.
  56.  If you have one of these, do not specify -DUNIX; you will 
  57.  have to live with the gnuplot error messages.  This is the
  58.  case for vt100 terminals.  If the -DUNIX option is not 
  59.  specified, temporary files will be written to the current 
  60.  directory rather than /tmp.
  61.  
  62. END
  63.  
  64. NOTE
  65.  
  66.  FIT2  a non-linear fitting program for OS/2 2.x.  If you 
  67.  are using UNIX, you might try OS/2 2.1, where this program
  68.  was developed and intended for use.
  69.  
  70.  Version 1.5 beta
  71.  
  72.  Written by Michael Courtney, servant of the Kingdom of God.
  73.  
  74.  Jesus Christ can take away your fear.
  75.  
  76.  I hope you find this program useful, but there are no warranties
  77.  and no guarantees.
  78.  
  79.  Send bug reports, comments and suggestions to michael@amo.mit.edu
  80. END
  81.  
  82. GENERAL
  83.  
  84.  Fit2 is a non-linear least-squares fitting program. It uses
  85.  the Levenberg-Marquardt method to attempt to minimize the 
  86.  least-squares error between a data file and a model 
  87.  function.  See the books, DATA REDUCTION AND ERROR ANALYSIS
  88.  IN THE PHYSICAL SCIENCES by P. R. Bevington and NUMERICAL 
  89.  RECIPES IN C by W. H. Press et. al. for more information 
  90.  on this method.
  91.  
  92.  Due to the generality of the fitting function allowed,
  93.  and the possible weirdness of the error function in
  94.  parameter space, convergance to the true minimum is not
  95.  guaranteed.  Therefore, it is important to have good
  96.  initial guesses for the parameters.  It is a good idea to 
  97.  graph your data and the fitting function with your
  98.  initial guesses, and tweak the initial guesses until the 
  99.  fitting function is close to the data.  Most functions
  100.  with three or four parameters will converge quickly if the
  101.  initial guesses are in the right ballpark.  If you have 
  102.  more than four parameters, you may have to tell the program
  103.  to vary only four at a time (the sp command).  When the 
  104.  parameters you are varying affect a subset of the data 
  105.  much more than the rest, you should window the data 
  106.  accordingly (the wi command). If these tricks do not work, 
  107.  check and make sure that the function is computing the 
  108.  proper value of the function and derivatives with respect 
  109.  to the parameters.  You have to check your source for this. 
  110.  A sign error is disasterous.  It will cause the guess for 
  111.  the parameter to be further from the correct value than 
  112.  the current value.
  113.  
  114.  The Levenberg-Marquardt method will work for functions
  115.  which are linear in the parameters.  It is not as fast as 
  116.  linear regression, and it is not guaranteed to converge to
  117.  an absolute minimum.  However, it will do in a pinch and
  118.  it is actually a little more robust if your basis functions 
  119.  are nearly linearly dependent.  Of course, if your basis 
  120.  functions are nearly linearly independent then your 
  121.  parameters will be strongly correlated, and you will have 
  122.  to sort what is meaningful and what is not.
  123.  
  124.  This program was written by Michael Courtney.  I consider 
  125.  this a beta version of the program.  I retain all rights 
  126.  to the program. You may use the program and alter the 
  127.  source to fit your needs. You may not distribute altered 
  128.  source or executable unless you obtain my permission.  You 
  129.  may port this program to other platforms if you wish.  It 
  130.  should compile and run almost unaltered on the NeXT 
  131.  platform and most Unix platforms.  You may not sell the 
  132.  program or source or receive any money for its 
  133.  distribition.  The program is provided "as is" and is 
  134.  without warranty of guarantee of any kind.  The author 
  135.  assumes no responsibility of any kind for anything the 
  136.  program does. If you use this program regularly, it is 
  137.  required that you send me email and let me know you are 
  138.  using it.  No payment is required.
  139.  
  140.  Please report bugs and suggestions to Michael Courtney
  141.  at michael@amo.mit.edu.  I will consider bugs to have
  142.  a higher priority than suggestions, although suggestions 
  143.  are welcome.
  144.  
  145.  I am considering the following future enhancements to the
  146.  program:
  147.  
  148.  1. Multiple data sets -- the ability to simultaneously fit 
  149.  multiple data sets to different functions which share 
  150.  common parameters.  Currently, you can effectively 
  151.  accomplish this, see Multiple Data Sets.
  152.  
  153.  2. Ability to handle binary files.
  154.  
  155.  3. Command line history.
  156.  
  157.  Please let me know if any of these enhancements are of 
  158.  interest to you.
  159. END
  160.  
  161. IMPROVEMENTS and CHANGES
  162.  
  163.  This is the 1.5 beta version of the program.  
  164.  
  165.  The improvements over the 1.4 beta are the following:
  166.  
  167.  1. Ability to take commands from a file.  See the do command. 
  168.  
  169.  2. fit2 can now be compiled with Cset++ under OS/2 2.x.
  170.  
  171.  3. More bug fixes.
  172.  
  173.  4. The noset command.
  174.  
  175.  The improvements over the 1.3 beta are the following:
  176.  
  177.  1. New plotting routine under OS/2 allows viewing
  178.  of a plot of every attempted fit.  See the fp command.
  179.  
  180.  2. Minor bug fixes.
  181.  
  182.  3. A simple way to estimate errors in the parameters.
  183.  See the command er.
  184.  
  185.  The improvements over the 1.2 beta are the following:
  186.  
  187.  1. Linear Least-Squares Fitting
  188.  
  189.  2. Minor bug fixes.
  190.  
  191.  3. Can change one parameter at a time.  Se the cp command.
  192.  
  193. END
  194.  
  195. COMMANDS
  196.  
  197.         The following can be executed at the "fit>" prompt:
  198.         
  199.         name     meaning
  200.         
  201.         help
  202.         quit
  203.         fn       function
  204.         ip       initialize parameters
  205.         cp       change one parameter
  206.         sp       select parameters (to vary)
  207.         gd       get data
  208.         fi       fit
  209.         pp       print parameters
  210.         wp       write parameters (to a file)
  211.         wf       write fit (data to a file)
  212.         rp       read parameters (from a file)
  213.         wt       weight (for fitting)
  214.         co       covariant matrix 
  215.         order    order (of data colums in file)
  216.         ad       allocate data array
  217.         lf       lists functions available
  218.         gr       graphing flag
  219.         plot     plot data and fit
  220.         load     load a gnuplot command file
  221.         set      set something in gnuplot
  222.         noset    stops fit2 from setting things in gnuplot
  223.         wi       windows data
  224.         ve       changes verbosity
  225.         pr       plot residual errors
  226.         sh       shows current settings
  227.         md       makes data
  228.         de       debug
  229.         ru       run a program
  230.         gn       sends a command to gnuplot
  231.         li       linear least squares fit
  232.         pa       pauses for a number of seconds
  233.         fp       turns the use of fitplot.exe on and off
  234.         er       estimate errors in the parameters
  235.         do       takes commands from a file
  236. END
  237.  
  238. FILES
  239.  
  240.         fit2 opens and stores data in several files.  
  241.  fit.tmp is used if the function is plotted to a file.  
  242.  fit.dat is used as a default filename if none is specified 
  243.  with the wf command. The wp command stores the parameters 
  244.  in the file a.dat. In addition, the text output of gnuplot 
  245.  which is sent to stderr is written in the file gnuout.  
  246.  On non-unix machines, fit2 does not erase any of these 
  247.  files, unless it overwites them.  On UNIX machines fit.tmp 
  248.  and gnuout are written in the /tmp directory.  They are 
  249.  erased ewhen the program exits, unless debugging is on.  
  250.  If the debug flag is non-zero, lamda is written to a file 
  251.  called lamda.sts on every successful iteration.  lamda 
  252.  controls how much the paramerers are changed in attempting
  253.  to reduce chisqr.
  254. END
  255.  
  256. fn     Usage: fn name
  257.  
  258.         fn chooses a function for fitting.
  259.  
  260.         Example: "fn gauss" chooses to fit to a gaussian.
  261. END
  262.  
  263. ip     Usage: ip a0 a1 a2 ...
  264.  
  265.         ip initializes the fitting parameters.  If the number
  266.  of parameters is changed, the parameters are initialized to 5
  267.  when the fn command is  executed.  ip can be used at any time to
  268.  change the values of the parameters. If you want to leave some
  269.  parameters unchanged,enter a * in place of the number.  You must
  270.  enter either a number or a * for all of the parameters.
  271.  
  272.         Example: "ip 13.7 * 12" changes a0 to 13.7, leaves 
  273.  a1 the same, and changes a2 to 12 for a three parameter fit.
  274. END
  275.  
  276. cp        Usage: cp # #
  277.  
  278.         cp changes the parameter specified by the first
  279.  number to the value specified by the second number.  The 
  280.  first number must be in the range of parameters ( >= 0 and 
  281.  less than the number of parameters).
  282.  
  283.         Example "cp 3 3.141" changes a3 to 3.141 and leaves
  284.  all the other parameters unchanged.
  285. END
  286.  
  287. sp     Usage: sp # # #
  288.  
  289.         sp selects which parameters to vary.  By default,
  290.  all parameters are selected to be varied when the fn 
  291.  command is executed.  If you only wanted to vary 
  292.  parameters a0 and a2 of a three parameter fit, you would 
  293.  issue the command:
  294.  
  295.         Example: "sp 0 2"
  296. END
  297.  
  298. gd     Usage: gd filename
  299.  
  300.         gd geta the data from a file.  Data should be in an 
  301.  ascii file with between two and 20 columns. For fitting
  302.  functions of more than one independent variable, select a 
  303.  function with the number of independent variables that you 
  304.  want to fit to before reading in data.  This will allow the 
  305.  program to default to interpreting columns 1 through n 
  306.  (where n is the number of independent variables of the
  307.  current function) as representing the independent variables
  308.  in order.  By default, the (n+1)th column is interpreted to
  309.  be y(x0 ... xn) and the (n+2)th column is interpreted as 
  310.  the experimental error in the measured y.  If you wish to 
  311.  assign the columns in your data file differently, or if you
  312.  read in the data before choosing a function (for more than 
  313.  1 independent variable), you will have to use the order 
  314.  command.
  315.  
  316.  By default, if no function has been selected, or if a
  317.  function of one independent variable has been selected,
  318.  the first column is x, the second is y, and if there is a
  319.  third, it is assumed to be the error in y.  If you wish to
  320.  assign different columns to be x, y, and delta y, use the
  321.  order command.  By default, the program can handle a file
  322.  with five columns and 1024 rows.  The ad command can be 
  323.  used to allocate the data array differently and handle up 
  324.  to 23 columns and as many rows as memory allows.
  325.  
  326.  Lines in a data file beginning with the '#' character are taken
  327.  to be comments.
  328.  
  329. END
  330.  
  331. fi     Usage: fi [iterations]
  332.  
  333.         fi fits the data using the non-linear fitting
  334.  algorithm. Iterations is the  number of iterations between 
  335.  plots.  If no number it given, it defaults the last number 
  336.  used.  If none was ever entered, it defaults to 20. After 
  337.  this number of iterations, the data and fit are plotted, if
  338.  graphing if selected.  (It is by default.  See the gr 
  339.  command.)  You are then given the option to quit iterating 
  340.  (q enter), continue iterating and turn on graphing (g enter), 
  341.  continue iterating and turn off graphing
  342.  (n enter), or continue with the same graphing status.  
  343.  
  344.  If the fi command is executed from a command file, the
  345.  fit stops after the selected number of iterations and
  346.  does not prompt for user input.  This is to facilitate
  347.  batch processing.
  348.  
  349.  There is no way in general to be sure chisqr is at an 
  350.  absolute minimum. It might just be at a local minimum. 
  351.  Starting the fit with several sets of values of initial 
  352.  parameters and having every fit that converges find the 
  353.  same set of final values and same chisqr gives some 
  354.  confidence. Looking at the graph at least tells us we're 
  355.  not too far away.
  356.  
  357.  It is possible to estimate the errors in the parameters 
  358.  once chisqr is minimized.  Rather than build this into the
  359.  program for people to use with more confidence than
  360.  warranted, I merely make all the information you need
  361.  available. You should look at the references and figure it 
  362.  out.  This way you will have an idea of how unreliable 
  363.  error estimates on the parameters can be.
  364. END
  365.  
  366. li      Usage: li
  367.  
  368.         li fits the data using a linear fitting algorithm.
  369.  No iteration is required since the best-fit parameters are
  370.  uniquely determined by the data and basis functions. 
  371.  The linear fitting algorithm used is the simplest possible. 
  372.  A matrix equation is set up and solved by Gauss-Jordan
  373.  elimination.  A singular matrix will cause a failure of the
  374.  method and probably indicates a linearly dependent basis set. 
  375.  A near-singular matrix will cause inaccuracies in parameter
  376.  values.  
  377.  
  378.  li will usually work very well for less than 6 or so basis
  379.  functions and reasonably well for up to about 10 basis
  380.  functions. If you have problems with singular matrices,
  381.  doubt the accuracy of your parameters, or want to
  382.  incorporate errors in the independent parameters, I suggest
  383.  that you use the li to obtain initial guesses and then use
  384.  fi for to find the final parameter values.  fi will usually
  385.  converge quickly if you start with initial guesses obtained
  386.  from li.
  387.  
  388.  You should be aware that fitting to a subset of parameters
  389.  with the sp command has a different effect with li than it 
  390.  does with fi.  With fi, the selected parameters are varied 
  391.  while the unselected parameters are held fixed.  With li, 
  392.  the selected parameters really define which basis functions
  393.  are incorporated in the fit.  These are the only parameters
  394.  found,  the other parameters are set to zero.  This may be 
  395.  inconvenient in certain situations, but it reflects a basic 
  396.  difference between linear and non-linear fitting.
  397. END
  398.  
  399. pp     Usage: pp
  400.  
  401.         pp prints the current value of the parameters to the
  402.  screen.
  403. END
  404.  
  405. wp     Usage: wp [filename] [mode]
  406.  
  407.         wp writes the parameters to a file.  If no filename
  408.  is given, parameters are written to the file "a.dat".  mode
  409.  should be "a" (for append) or "w" for overwrite.  The
  410.  default mode is "w".
  411.  
  412.         Examples: 
  413.  "wp" writes the parameters to the file "a.dat", overwriting
  414.  the file if it exists.  
  415.  
  416.  "wp params.dat a" writes the parameters to the file
  417.  params.dat, appending then on to the end of the file if  it
  418.  already exists.
  419. END
  420.  
  421. wf     Usage: wf [filename]
  422.  
  423.         wf writes the fitted data to a file, overwriting the
  424.  file if it exists.  If no filename is given, data is 
  425.  written to the file "fit.dat".  The fitted data is the 
  426.  value of the fitting function evaluated at the value of x 
  427.  of the current data set using the current parameters.
  428. END
  429.  
  430. md      Usage: md filename xmin0 xmax0 xstep0 xmin1 xmax1 xstep1
  431.  
  432.         md makes a trial data set.  It's primary use is in
  433.  testing new fitting functions.  At this time, it is only 
  434.  implemented for functions of one or two independent 
  435.  variables.  The trial data set is created using the current
  436.  parameter values and the current fitting function.
  437.  
  438.  Examples:
  439.  
  440.  fit2> fn gauss        /* defines fitting function as gauss */
  441.  fit2> ip 5 1 1        /* initialized parameters */
  442.  fit2> md test 0 10 1  /* makes data for 0 <= x0 <= 10*/
  443.  fit2> gd test         /* reads in data */
  444.  fit2> ip 5.1 2 1      /* changes parameters */
  445.  fit2> fi              /* test to see if fit finds real parameters */
  446.  fit2> fn xyquad       /* defines fitting function as xyquad */
  447.  fit2> ip 5 5 5 5 5 5  /* initialized parameters */
  448.  fit2> md test 0 10 1 0 10 1
  449.                       /* makes data for 0 <= x0 <=10 and 0 <= x1 <= 10*/
  450.  fit2> gd test         /* reads in data */
  451.  fit2> ip 1 1 1 1 1 1  /* changes parameters */
  452.  fit2> fi              /* test to see if fit finds real parameters */
  453. END
  454.  
  455. rp     Usage: rp [filename]
  456.  
  457.         rp reads the parameters from a file.  If no file is
  458.  given, it attempts to read the parameters from the file 
  459.  "a.dat".
  460. END
  461.  
  462. de      Usage: de flag
  463.  
  464.         de changes the debugging status of the program. 
  465.  Flag is 0 for no debugging, 1 for light debugging, and 2
  466.  for heavy debugging. Only certain sections of code have
  467.  been set up for this.  Other sections will be set up as I 
  468.  need to debug them.  This option is intended mainly for 
  469.  use of someone altering the program. If the debugging level
  470.  is 1, all of the commands sent to gnuplot are printed, 
  471.  along with other information.
  472. END
  473.  
  474. sh
  475.  
  476.         sh shows the value of current settings.
  477. END
  478.  
  479. wt     Usage: wt [none stat inst other]
  480.  
  481.         The fitting function tries to minimize chisqr, where
  482.  chisqr = sum( ((yi - f(xi))/sigmai)**2 ).  That is, chisqr 
  483.  is the sum of the squared error of the difference between 
  484.  the data and the fitting function, except that each term in 
  485.  the sum is weighted by sigmai**2.  The "wt" command chooses
  486.  the type of weighting.  It chooses what to use for sigma.
  487.  Errors in the independent parameters can also be used for
  488.  non-linear fitting.  See the order command for details.
  489.         The following weighting options are available:
  490.  
  491.  none..........no weighting, all sigma's are equal to one.
  492.  statistical...sigmai = sqrt(yi)
  493.  instrumental..sigmai = deltayi, as in data file
  494.  other.........sigmai = yi
  495.  
  496.         Example: "wt s" selects statistical weighting.
  497. END
  498.  
  499. co     Usage: co [filename]
  500.  
  501.         co prints the covariant matrix.  It will overwrite
  502.  the file if a file of the same name exists.  If no filename
  503.  is given, the covariant matrix is written to the screen. 
  504.  The covariant matrix can be used to estimate the error of
  505.  the fit parameters.
  506. END
  507.  
  508. er      Usage: er factor
  509.  
  510.         er provides a simple way to estimate the errors in the
  511.  parameters.  The algorithm is very simple, and the answer it
  512.  gives is intuitively satisfying, but not statistically rigorous.
  513.  The algorithm varies one parameter at a time and finds two
  514.  values of the parameter where chisqr is increased by the given
  515.  factor.  An increase of 10-20% in chisqr should give a reasonable
  516.  estimate of the errors in the parameter, so I suggest a factor
  517.  of 1.1 or 1.2.  For factors larger than 2.0, the algorithm may 
  518.  not converge, and you answers would not make sense as error
  519.  estimates on the parameters.  If the output is NAN or INF, try
  520.  using a factor closer to 1.
  521.  
  522. END
  523.  
  524. order   Usage: order x0col ... xncol ycol sigycol sigx0col ... sigxncol
  525.  
  526.         order assigns significance to the columns in the 
  527.  internal data matrix.  When a data file is read with the gd 
  528.  command, the first column in the file is stored in the 
  529.  data[0].  (The 0th column of an 2-D array).  The second 
  530.  column is stored in data[1], etc.  By default, these rows 
  531.  are interpteted in a certain way (See the gd command).  The
  532.  order command is used to change the default behavior.
  533.  
  534.  Errors in the independent variables can be used in the fit 
  535.  by using techniques of error propagation to calclate a 
  536.  corresponding error in y.  That is:
  537.  
  538.  sigy = sqrt( sigy*sigy + sigx*sigx*(dy/dx)*(dy/dx) ).
  539.  
  540.  Each data point has its own value of sigmax's and sigmay.
  541.  Each sigx must be in a column in the data file.  The
  542.  weighting for sigy should be statistical, instrumental or 
  543.  other if sigx is considered in the fit.  You should not 
  544.  select no weighting if you want to use sigx.  If the order
  545.  command selects a column to be sigx, then this information
  546.  is used for the fit.  If you wish to not use this 
  547.  information, assign sigxcol to be -1 (the default value).
  548.         If the fitting algorithm has a problem converging
  549.  when using sigx, try the fit without using sigx.  Then take
  550.  those parameters as the initial parameters for the fit 
  551.  considering sigx. Note that errors in the independent
  552.  variables are not considered during linear least squares 
  553.  fitting.
  554.  
  555.         Examples for one independent variable:
  556.  
  557.  "order 2 1 0"  x0 is the third column in the file, y is the
  558.  second column, sigy is the first column.
  559.  
  560.  "order 1 4" x0 is the second column, y is the fifth column,
  561.  sigy is not specified.
  562.  
  563.  "order 0 1 2 3" x0 is the first column in the file, y is
  564.  the second column, sigy is the third column, sigx0 is the
  565.  fourth column and is used in the fit.
  566.  
  567.  "order 0 1 2 -1" x0 is the first column in the file, y is
  568.  the second column, sigy is the third column, sigx0 is not
  569.  used.
  570.  
  571.         Examples for two independent variables:
  572.  
  573.  "order 2 1 0 3"  x0 is the third column in the file, x1 is
  574.  the second column, y is the first column, sigy is the
  575.  third column.
  576.  
  577.  "order 1 4 2" x0 is the second column, x1 is the fifth
  578.  column, y is the third column, sigy is not specified.
  579.  
  580.  "order 0 1 2 3 4 5" x0 is the first column in the file, x1
  581.  is the second column, y is the third column, sigy is the
  582.  fourth, sigx0 is in the fifth column and is used in the
  583.  fit, sigx1 is in the sixth column and is used in the fit.
  584.  
  585.  "order 0 1 2 3 -1 -1" x0 is the first column in the file,
  586.  x1 is the second column, y is the third column, sigy is the
  587.  fourth, sigx0 and sigx1 are not used in the fit.
  588. END
  589.  
  590. ad     Usage: ad columns rows
  591.  
  592.         ad re-allocates the internal data matrix.  It is 8
  593.  columns and 1024 rows by default.  You can have up to 23
  594.  columns and as many rows as memory allows.  Three rows are
  595.  used internally, and up to 20 rows can be used for data
  596.  from your input file.  The ad command erases any data
  597.  currently in memory.
  598.  
  599.         Example: ad 11 4096
  600. END
  601.  
  602. lf     Usage: lf
  603.  
  604.         lf lists the functions available for fitting.
  605. END
  606.  
  607. gr     Usage: gr flag 
  608.  
  609.         The gr command turns the graphing on and off.  "gr 0"
  610.  turns graphing off.  "gr 1" turns graphing on.  Graphing is
  611.  on by default.
  612. END
  613.  
  614. fp     Usage: fp flag
  615.  
  616.         The fp command turns the use of the fitplot.exe
  617.  program on and off.  The fitplot.exe program is a fast
  618.  plotting program which is used to plot the data and
  619.  attempted fit every iteration.  This is useful if you want
  620.  to see what the Levenberg-Marquardt algorithm is doing.
  621.  The use of fitplot.exe is off by default, although if there
  622.  are any command line arguments to fit2.exe, the use of
  623.  fitplot.exe is turned on.
  624.  
  625.  Some people have found that use of this plotting program
  626.  will hang the message queue on slower machines.  I have not
  627.  been able to reproduce the problem.  If this occurs, I suggest
  628.  you stick to gnuplot for plotting.
  629. END
  630.  
  631. plot   Usage: plot
  632.  
  633.         plot plots the data and fitting function with the
  634.  current parameters.
  635. END
  636.  
  637. load   Usage: load filename
  638.  
  639.         load loads and executes a gnuplot command file.
  640. END
  641.  
  642. set    Usage: set gnuplot stuff
  643.  
  644.         The entire set command is sent to gnuplot.
  645. END
  646.  
  647. gnuplot
  648.  
  649.         Gnuplot is is an interactive plotting program. To
  650.  use the graphing capability of the fit program, you must
  651.  have the gnuplot program correctly installed in your system
  652.  and it must be in a directory in the current path.
  653. END
  654.  
  655. wi     Usage: wi [one or more numbers]
  656.  
  657.         wi selects data windowing.  It is used if you want
  658.  to fit the data in a certain range of x values.  If wi has
  659.  one argument, it turns windowing on and off.  "wi 1" turns
  660.  windowing on.  "wi 0" turns windowing off.  If wi has more
  661.  than two arguments, windowing is turned on, and the
  662.  arguments are the minimum and maximum x values used in
  663.  fitting.  In other words, chisqr is computed only for
  664.  xmin <= x <= xmax.
  665.  
  666.         Examples: 
  667.  
  668.  "wi 30 100" tells the fi command to perform the fit using
  669.  only x values between 30 and 100.
  670.  
  671.  "wi 30 100 2 10" tells the fi command to perform the fit
  672.  using only x0 values between 30 and 100 and x1 values
  673.  between 2 and 10.
  674. END
  675.  
  676. ve     Usage: ve flag
  677.  
  678.         If flag = 0, the fit command gives little output. If
  679.  flag = 1, the fit command only gives the paramters every
  680.  iteration.  If flag = 2, the output is very verbose.
  681. END
  682.  
  683. noset  Usage: noset flag
  684.  
  685.         If flag = 0, then fit2 issues the set command to 
  686.  gnuplot often for setting ranges, labels, titles, etc.
  687.  If flag = 1, fit2 only sends gnuplot a set command when
  688.  absolutely necessary for performing the requested operation.
  689. END
  690.  
  691. pr      Usage: pr flag
  692.  
  693.         pr plots residual errors.  If there is no flag or
  694.  flag = 1, yfit vs. y is plotted.  If flag = 2, (y-yfit) vs.
  695.  x is plotted.
  696. END
  697.  
  698. run     Usage: run command line
  699.  
  700.         run sends a command line to the default command
  701.  processor. It is used to run a program from within fit2.
  702.  
  703.         Example: run dir *.dat
  704. END
  705.  
  706. gn      Usage: gn gnuplot command
  707.  
  708.         gn sends a command to the gnuplot command processor.
  709.  It is used to execute gnuplot commands from within fit2.
  710.  You need to send a correct gnuplot command.  You will get
  711.  no error message if you do not.
  712. END
  713.  
  714. pa      Usage: pa seconds
  715.  
  716.  If seconds = -1, the program is paused until enter is hit.
  717.  
  718. END
  719.  
  720. do      Usage: do file
  721.  
  722.  do executes commands from a command file.  Lines beginning with # are
  723.  comments.  Blank lines are skipped.  All other lines are executed.
  724. END
  725.  
  726. functions
  727.  
  728.         There are several built in functions.  Other
  729.  functions can be added by adding them to the file
  730.  funclib2.c and recompiling.  See that file for details. 
  731.  The built in functions are: gauss, gaussc, ngauss, lorenz,
  732.  2lorenz, line, poly, nexp, and xyquad.
  733. END
  734.  
  735. gauss
  736.  
  737.         The function gauss is a gaussian of the form:
  738.  f(x) = a2*exp(-((x-a0)/a1)**2).  Fitting to this function
  739.  converges easily if your initial guesses are even close.
  740.  For gauss and most peak-type functions, your initial
  741.  guesses will probably converge if your function peaks are a
  742.  little shorter and wider than you data peaks.
  743. END
  744.  
  745. gaussc
  746.  
  747.         The function gauss is a gaussian plus a constant.
  748.  f(x) = a2*exp(-((x-a0)/a1)**2) + a3.  Fitting to this
  749.  function converges easily.
  750. END
  751.  
  752. ngauss
  753.  
  754.         This function is a sum of gaussians plus a constant.
  755.  It uses a variable number of parameters.  The number you
  756.  want must be chosen when you select the function.  The
  757.  function has the form:
  758.  f(x) = sum( a[i+2]*exp(-((x-ai)/a[i+1])**2) ) + a[n-1]. 
  759.  You must choose 3*n+1 parameters, where n is the number of
  760.  gaussians you want. This function converges slowly for more
  761.  than 2 gaussians, but it usually does converge.  If the
  762.  peaks in your data are separated by several widths, you
  763.  should window the data and fit the peaks separately first,
  764.  and then do a final fit on the whole data set.
  765. END
  766.  
  767. lorenz
  768.  
  769.         This is a lorenzian function of the form:
  770.  f(x) = a2/(4*(x-a0)**2 + a1).  I choose not to use the
  771.  usual form since, I thought making the form simple in
  772.  regards to the parameters might make for more robust
  773.  fitting.  You have to think to eyeball the initial
  774.  paremeters though.  If your data is a lorenzian, it will 
  775.  converge without much trouble.  If your data is not really
  776.  a lorenzian you may have trouble.  The gaussian is a
  777.  better choice to fit peaks that are not well characterized
  778.  by a particular function.
  779. END
  780.  
  781. 2lorenz
  782.  
  783.         This is the sum of two lorenzians and it has the
  784.  form: f(x) = a2/(4*(x-a0)**2 + a1) + a5/(4*(x-a3)**2 + a4). 
  785.  It sometimes takes some effort to get a fit to this
  786.  function to converge.
  787. END
  788.  
  789. line
  790.  
  791.         f(x) = a0 + a1*x.  Piece of cake.
  792. END
  793.  
  794. poly
  795.  
  796.         f(x) = sum(ai*(x**i)).  Decent initial guesses and
  797.  fourth order or less converge easily and quickly.  Higher
  798.  orders might take some work.  Using li to obtain initial
  799.  guesses and fi for final parameter values is best for
  800.  polynomials higher than fourth order.
  801. END
  802.  
  803. nexp
  804.  
  805.         This function is the sum of decaying exponentials. 
  806.  It has  the form: 
  807.  f(x) = sum( step(a[i])*a[i+2]*exp((x-a[i])/a[i+1]) )
  808.  + a[n-1], where step(a) = 0 if x < a.  step(a) = 1 if 
  809.  x >= a.  You need to tell the program how many parameters
  810.  you want.  4 parameters gives you one exponential, 7 gives
  811.  you two, etc.  If you know the offset, you should
  812.  initialize properly and not vary that parameter.  For 
  813.  example, most decaying exponentials are triggered by some
  814.  event. If you know the time of the event, don't vary that
  815.  parameter.
  816. END 
  817.  
  818. xyquad
  819.  
  820.         f(u,v) = a0 + a1*u + a2*v + a3*u*u + a4*v*v + a5*u*v.
  821.  u and v are used instead of x and y or x0 and x1, because
  822.  gnuplot needs to plot the data parametrically.  The linear
  823.  fitting  algorithm works pretty well, but I recommend the
  824.  result be checked with a few iterations of the L-M
  825.  algorithm, for example, issue the command, "fi 5" after the
  826.  "li" command.
  827. END
  828.  
  829. sincos
  830.  
  831.         f(x) = a0 + a[i]*sin(a[i+1]*x)
  832.  + a[i+2]*cos(a[i+3]*x).
  833.  You need good initial guess to get this fitting function to
  834.  converge quickly, if at all.  You will do well to get the
  835.  frequencies close.  If the zeros of your fitting function
  836.  with your initial parameters are close to the zeroes of
  837.  your data, you have a good chance of converging.  For
  838.  special cases like Fourier series, you probably want a
  839.  specialized function.  You should take a Fourier transform
  840.  if that is what you reeally want.
  841. END
  842.  
  843. conic
  844.  
  845.         conic does not work very well and I do not reccomend
  846.  its use.
  847. END
  848.  
  849. Multiple Data Sets
  850.  
  851.         Let's say that you have several different data sets
  852.  that you want to fit to functions which share some common
  853.  parameters. You can simulate the functionality of multiple
  854.  data sets.
  855.  
  856.  Put all of your data in the same file , with the same
  857.  columns being used for x0, x1 . . . xn, y, any sigma's etc.
  858.  Add an extra row to the file containing a number to
  859.  uniquely identify the data set.  Define your function for 
  860.  n+1 independent variables, and assign the extra row to be
  861.  x(n+1).  The (n+1)th independent variable will be passed to
  862.  your fitting function.  Use it to decide which data set you
  863.  are using and return the appropriate function value and
  864.  derivatives.
  865.  
  866.  Sure, it's a kludge, but it's better than nothing for now.
  867. End
  868.  
  869.