Astronomical Applications Department, U.S. Naval Observatory Linear Least Squares Page 10
:=
foo
(
)
optimize
(
)
makeproc
,
tmp
=
parameters [
]
, ,
N y t
foo
, ,
N y t
proc
(
)
:=
local
;
,
, , , ,
,
t8 t11 t4 t5 t1 tmp t2
:=
tmp
(
)
array ..
1 2 ;
:=
t1
(
)
sum
,
[ ]
y i
=
i
..
1 N ;
:=
t2
(
)
sum
,
^
[ ]
t i 2
=
i
..
1 N ;
:=
t4
(
)
sum
,
[ ]
t i
=
i
..
1 N ;
:=
t5
(
)
sum
,
[ ]
t i
[ ]
y i
=
i
..
1 N ;
:=
t8
^
t4 2;
:=
t11
/
(
)
1
- +
t8
t2 N ;
:=
[ ]
tmp 1
(
)
-
t1 t2
t4 t5 t11;
:=
[ ]
tmp 2
(
)
-
t5 N
t4 t1 t11;
tmp
end
(
)
writeto "d:/Maple/test.p"
(
)
print foo
(
)
writeto terminal
This is simple and straightforward in this example. Later on, we will see that the solutions can get
rather unwieldy, but that the optimized procedures created from them are still relatively simple.
Polynomial of degree 2
:=
printlevel
2
leastsqrs
, , ,
=
Y
+
+
A B t
i
C t
i
2
t i [
]
, ,
A B C
leastsqrs[0]: normal equations
=
-
+
+
+
2 S
0
2 A N 2 B T
1
2 C T
2
0
=
-
+
+
+
2 S
1
2 A T
1
2 B T
2
2 C T
3
0
=
-
+
+
+
2 S
2
2 A T
2
2 B T
3
2 C T
4
0
leastsqrs[0]: Solving the normal equations...
leastsqrs[0]: substitution list
2
=
i 1
N
t
i
=
i 1
N
t
i
2
=
i 1
N
t
i
3
=
i 1
N
t
i
3 2
N
=
i 1
N
t
i
2 3
=
i 1
N
t
i
4
N
=
i 1
N
t
i
2
-
+
+
-
=
=
i 1
N
t
i
4
=
i 1
N
t
i
2
+
=
S
0
=
i 1
N
Y
i
=
T
1
=
i 1
N
t
i
=
T
2
=
i 1
N
t
i
2
=
S
1
=
i 1
N
t
i
Y
i
=
T
3
=
i 1
N
t
i
3
,
,
,
,
,
,
Page 10