home *** CD-ROM | disk | FTP | other *** search
/ Dr. CD ROM (Annual Premium Edition) / premium.zip / premium / IBMOS2_1 / LSQRFT13.ZIP / fit.hlp < prev    next >
Text File  |  1993-07-10  |  29KB  |  745 lines

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