An Automated Linear Least Squares Solution
Generator
Marc A. Murison
Astronomical Applications Department
U.S. Naval Observatory
Washington, DC
murison@riemann.usno.navy.mil
http://aa.usno.navy.mil/murison/
26 May, 1999
1. Introduction
In day-to-day work, one often has need to perform a quick linear least squares calculation for
some model which approximates a physical process. Since the model is likely to be something other
than simple linear regression, one winds up (often re-) deriving the appropriate normal equations and
solving for the model parameters. This is wasted effort, thanks to the availability of computer algebra
systems, in which it is easy to automate this process. In the section which follows, I illustrate the
basic "quick and dirty" linear least squares process by means of a simple example. In section 3, I
present a Maple procedure that performs the algebra autmatically for any model that is linear in the
parameters, and in section 4 are a few examples of its usage.
2. A Linear Least Squares Example
Start with a simple second degree polynomial as our model:
:=
model
+
+
A B t
i
C t
i
2
.
Then the
2
statistic is
=
2
=
i 1
N
(
)
-
y
i
model
2
.
=
2
=
i 1
N
- -
-
y
i
A B t
i
C t
i
2 2
where the sum is over N available data points, and the
y
i
are the data values, measured at times
t
i
. In
keeping with the "quick and dirty" premise, we do not take into account a priori any weighting of the
data. It is a simple matter to add weight factors into the solutions afterwards; including them now
would serve only to clutter up the notation.
Page 1