Department of
Physics & Astronomy

 
Academics
Courses
Events
Research
People
Facilities

Main Page
SFSU Home
  • Computer System
    • Remote Graphics Configuration Minsq Tutorial

Tutorial for Minsq (Least-Squares Fitting)

MINSQ is a program for doing a non-linear least-squares fit.
We illustrate the use of this program with a detailed explanation of how to fit a Gaussian to a set of data points.

Procedure

  • Belly up to a computer .

  • Make yourself a directory in your name, where you can store data, programs, etc.:
    		cd ~schmuck			# Unix
    		c:\usr\schmuck			# MS-Windows
    
  • Make a sub-directory, named "gaussian":
    		mkdir gaussian
    		cd gaussian
    
  • Enter:
    		MINSQ
    
    or, from MS-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.

  • 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.

  • "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, given previously as equation (5), 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 .

  • "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 .

  • Now enter the data. I give a sample set of data below; however, you should enter your histogram 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
    

  • Do the fit: "calculate," "least squares." For the data given, you should find:
    		P2 = 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.

  • Get a graph of the fit: "graphics," "draw plot," "printer output." Get two.

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 MS-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 123, convert this file to .jpg or .gif format, using Lview or some other program. The result should look like the example at the top of this page.
webwiz@stars.sfsu.edu