MINSQ - Non-Linear Least-Squares Fitting
( Project Lab Writeups |Computer Programs |sample graph )
Here we give a detailed explanation of how to do a Gaussian fit. We use the program MINSQ, installed on the project-lab PC's. This program is a general least-squares fitting program, and will optimize the functions parameters so as to best fit the data supplied. It will even work for non-linear parameters.
  1. Belly up to a computer .
  2. Make yourself a directory in your name, where you can store data, programs, etc.:
    	c:\usr\schmuck
    
    or
    	d:\usr\hero
    
    
    
  3. Make a sub-directory, named "gaussian."
  4. Enter
    	MINSQ
    
    or, from Windows, double-click on the MINSQ icon.

    The fitting program will load and execute. The following instructions are for MINSQ version 4.02. There is a later version, much more menu driven and mouse oriented. It is harder to use, though.

  5. Go through "Utilities" to "Misc," and set "default directory" to where you want your files to be stored, e.g., c:\usr\noah\gaussian\ . Otherwise when you save data, parameters, etc., you will have a terrible time finding them afterwards.
  6. "Get model," "define model." This defines the formula that will be fit to your data. (When you have a model file saved, you can use "retrieve model" instead.) Names are given to the variables and parameters. Here is what you should enter:
            independent variables:        FK
            dependent variables:          FN
    	parameters:                   FNTOT, X, SIGMA	
    	equations:
            	pi = 3.14159
    		fnwide = 1.	Width of the bins of your histogram.
    		fact1 = 1./(sqrt(2.*pi)*sigma)
    		fact2 = exp(-(fk-x)^2/(2.*sigma^2))
    		fn = fact1*fact2*fntot*fnwide
    
    These equations represent the form for the general Gaussian, as given in the writeup for lab B2, but multiplied by a parameter, fntot, which changes the normalization. FNTOT should come out to be equal to the total number of entries in the histogram, if the fit is good.

    Enter two returns to finish entering the model; it will be compiled. Now do "model compile." If the compilation works, without errors, save the model as the file d:\usr\schmuck\gaussian\gauss.eqn .

  7. "Get parameters," "enter parameters," then enter initial guesses for the three parameters. When done, "save parameters" to the file d:\usr\schmuck\gaussian\gauss.par .
  8. Now enter the data. I give a sample set of data below; you may want to enter it in, just to make sure the program is working. Then you would enter in your data. "get data," "enter:"
    	9. 	 3.
    	10.	25.
    	11.	132.
    	12.	111.
    	13.	19.
    	14.	6.
    	15.	1.  
    
    You could read in a data file from disk if you wanted to.  It should 
    start with a line with the 
    variable names:
    
    	FK  FN
    
    and it should end with the line
    	ENDDATA
    
  9. Do the fit: "calculate," "least squares." For the data given, you should find:
    		chi-squared = 46.381
    		FNTOT = 288.21
    		x = 11.411
    		F = 0.75806
    
    (The numbers for your data will be different, of course.)

    Now let the program determine the errors: "statistics," "90%," etc. For the data given, the errors on fntot, x, and F are 7, .02, and .02, respectively.

  10. Get a graph of the fit: "graphics," "draw plot," "printer output." Get two.
  11. Graphics File Conversion. There are (at least) two ways to convert the graph of your data on the screen into a computer file.
    • To make a PostScript file to use in LaTeX, go to plotter setup and configure the "Apple Laserwriter" option to write to a disk file. FTP this file to stars, and you can incorporate it into a paper.
    • To convert to a file which you can post on your web page, follow the following steps:
      • MINSQ should be running under Windows 3.11, in a separate window. If it is running in full-screen mode, press Alt-Enter to go to window mode.
      • Now copy the window to the clipboard, by pressing Alt-PrintScrn .
      • Open Paintbrush, and Paste in the contents of the clipboard.
      • Save as a file in .bmp format (256 colors is certainly good enough). Ideally, connect over the network to your stars file system, and save the file directly to your web-page directory.
      • If you saved the file locally, now either FTP the file to your account on stars, or connect over the network to your stars file system, and just move the file over using the File Manager.
      • Using one of the computers in TH 117, convert this file to .jpg or .gif format, using Lview or some other program. Here is an example of the result.