Maxima by Example, Chapter 14: Fitting a Model Function to Data
Ted Woollett
Chapter 14 provides examples of the use of a new set of Maxima functions (defined in fit.mac).
These new functions not only return the best-fit parameter values, but also the estimated parameter
uncertainties and the chi squared probability of the results.
These new functions assume one independent variable and one corresponding dependent
variable and are called fit_line, fit_slope, fit_y_intercept, lfit, and nlfit.
These new functions also allow for the use, while finding best fit model parameters,
of the estimated uncertainties of the measured dependent variable.
This chapter leans heavily on the text: Data Reduction and Error Analysis for the Physical Sciences, 3rd ed.,
by Philip R. Bevington and D. Keith Robinson.
- --mbe14.zip : Jan 15, 2017, zip file contains all following files.
- --mbe14fit.pdf : Jan 15, 2017, Maxima 5.36.1, 66 pages
- --mbe14fit.tex : Jan 15, 2017, Latex code file
- --fit.mac : Maxima code, Jan 15, 2017, Maxima 5.36.1
- --qdraw.mac : A Graphics Interface to draw2d: Jan 15, 2017, Maxima 5.36.1
- --coffee.dat : coffee cooling data file
- --mbe14-fit1.dat : Ex. 1 Data File
- --mbe14-fit2.dat : Ex. 2 Data File
- --mbe14-fit3.dat : Ex. 3 Data File
- --mbe14-fit4.dat : Ex. 4 Data File
- --mbe14-fit5.dat : Ex. 5 Data File
- --mbe14-fit6.dat : Ex. 6 Data File
- --mbe14-fit7.dat : Ex. 7 Data File
- --mbe14-fit8.dat : Ex. 8 Data File
Chapter 14 Topics
The most useful functions defined in fit.mac are listed here with the syntax. Mdata is a data matrix. sigL is a list of estimated measurement errors.
dof is the number of degrees of freedom (the number of data points minus the number of model parameters being fitted). ymodel is an expression
which includes some symbolic unknown parameters (to be found).
- fit_line (Mdata, sigL), Two Parameter Straight Line Fit
- fit_slope (Mdata, sigL, y-intercept), One Parameter Straight Line Fit, Given the Y-intercept
- fit_y_intercept (Mdata, sigL, slope), One Parameter Straight Line Fit, Given the Slope
- lfit (Mdata, sigL, ymodel, paramL), General Linear Fit
- nlfit (Mdata, sigL, ymodel, paramL, param-initL), General Nonlinear Fit, Levenberg-Marquardt Method
- moment (dataL)
- y_gaussian_PE (Mdata, dof, ymodel), Probable Data Error if Gaussian
- get_chi2 (Mdata, sigL, yfit_expr), ChiSquare Value Based on Fitted Parameters
- chi2 prob (chi2, dof), ChiSquare Probability and Reduced ChiSquare
- Vsearch (Mdata, sigL, ymodel, paramL, param-valuesL), Visual Search for Parameter Values
- grid search(Mdata, sigL,ymodel,paramL,param-initL,stepFactor), Grid Search Method
Nine examples are worked out in detail in the first part of the chapter.
Seven of these examples are taken from the text "Data Reduction and Error Analysis for the Physical Sciences," by Philip R. Bevington and D. Keith Robinson, 3rd Ed, 2003, McGraw Hill.
The chapter ends with a review of statistical concepts needed and
also a derivation of the matrix method used for the general linear fit function lfit.
A list of useful references concludes this chapter.
The text files fit.mac and qdraw.mac are free software: you can redistribute it and/or modify
it under the terms of the GNU GENERAL PUBLIC LICENSE, Version 2, June 1991,
as published by the Free Software Foundation. For more information see
the license information at the top of the pdf file.