Astronomical Applications Department, U.S. Naval Observatory Linear Least Squares Page 9
leastsqrs[0]: Forming the normal equations...
leastsqrs[0]: partials
=
=
i 1
N
(
)
-
+
+
2 y
i
2 A 2 B t
i
0
=
=
i 1
N
(
)
-
2 (
)
- -
y
i
A B t
i
t
i
0
leastsqrs[0]: summation terms
,
,
,
=
i 1
N
y
i
=
i 1
N
t
i
y
i
=
i 1
N
t
i
=
i 1
N
t
i
2
leastsqrs[0]: normal equations
=
-
+
+
2 S
0
2 A N 2 B T
1
0
=
-
+
+
2 S
1
2 A T
1
2 B T
2
0
leastsqrs[0]: Solving the normal equations...
leastsqrs[0]: raw solution(s)
,
=
A
-
S
0
T
2
T
1
S
1
-
+
T
1
2
T
2
N
=
B
-
-
+
S
1
N T
1
S
0
-
+
T
1
2
T
2
N
leastsqrs[0]: substitution list
,
,
,
,
=
-
+
=
i 1
N
t
i
2
=
i 1
N
t
i
2
N
=
S
0
=
i 1
N
y
i
=
S
1
=
i 1
N
t
i
y
i
=
T
1
=
i 1
N
t
i
=
T
2
=
i 1
N
t
i
2
leastsqrs[0]: Verifying the solution...
,
=
A
-
S
0
T
2
T
1
S
1
=
B
-
S
1
N T
1
S
0
The substitutions are stored in the global variable _subslist. Hence, the full solution is
(
)
eval
,
% _subslist
,
=
A
-
=
i 1
N
y
i
=
i 1
N
t
i
2
=
i 1
N
t
i
=
i 1
N
t
i
y
i
-
+
=
i 1
N
t
i
2
=
i 1
N
t
i
2
N
=
B
-
=
i 1
N
t
i
y
i
N
=
i 1
N
t
i
=
i 1
N
y
i
-
+
=
i 1
N
t
i
2
=
i 1
N
t
i
2
N
We can convert the solution into an optimized Maple procedure. This procedure can then be used to
evaluate the model with a set of data. It is easily saved to disk for conversion into a C or fortran
procedure -- also quite easy.
:=
tmp
(
)
array
(
)
map
,
x
( )
rhs x %
Page 9