Index: trunk/doc/pslib/psLibADD.tex
===================================================================
--- trunk/doc/pslib/psLibADD.tex	(revision 726)
+++ trunk/doc/pslib/psLibADD.tex	(revision 755)
@@ -1,4 +1,6 @@
-%%% $Id: psLibADD.tex,v 1.14 2004-05-19 00:48:05 price Exp $
+%%% $Id: psLibADD.tex,v 1.15 2004-05-22 02:43:54 price Exp $
 \documentclass[panstarrs]{panstarrs}
+
+\usepackage{amsmath}
 
 % basic document variables
@@ -24,5 +26,6 @@
 \RevisionsStart
 % version     Date         Description
-\theversion & 2003 Mar 11 & Hacking \\
+00 & 2004 Mar 11 & Hacking \\
+01 & 2004 May 21 & Added section on 2D Chebyshev fitting. \\
 \RevisionsEnd
 
@@ -507,7 +510,48 @@
 \end{center}
 
+\paragraph{Fitting a 2D Chebyshev Polynomial}
+
+Suppose we have an image, $z = z(x,y)$ with corresponding error
+estimates, $\sigma_z(x,y)$, and want to fit this with a 2D Chebyshev
+polynomial,
+\begin{equation}
+T(x,y) = \sum_{i,j} P_{i,j} T_i(x) T_j(y)
+\end{equation}
+where $T_i(x)$ is a Chebyshev polynomial in $x$ of order $i$
+(\S\ref{sec:polynomials}).  Then we can calculate the coefficients,
+$P_{i,j}$ by minimising $\chi^2$ in the standard manner:
+
+\begin{eqnarray}
+\chi^2 & = & \sum_{x,y} \left[ \frac{z(x,y) - P_{i,j} T_i(x) T_j(y)}{\sigma_z(x,y)} \right] ^2 \\
+\frac{\partial \chi^2}{\partial P_{k,l}} & = & -2 \sum_{x,y} \left[ \frac{z(x,y) - \sum_{i,j} P_{i,j} T_i(x) T_j(y)}{\sigma_z(x,y)} \right] \frac{T_k(x) T_l(y)}{\sigma_z(x,y)}
+\end{eqnarray}
+
+Setting the partial derivative to zero and assuming that the errors
+are approximately equal over the image (as is the case for background
+fitting), $\sigma_z(x,y) = \sigma = {\rm const}$, then:
+\begin{equation}
+\sum_{x,y} z(x,y) T_k(x) T_l(y) = \sum_{i,j} \sum_{x,y} P_{i,j} T_i(x) T_j(y) T_k(x) T_l(y)
+\end{equation}
+Then we use the orthogonality property of Chebyshev polynomials, namely,
+\begin{equation}
+\sum_{x=0}^N T_i(x) T_j(x) = \begin{cases} 0 & i \ne j \\
+N/2 & i=j \ne 0 \\
+N & i=j=0 \\
+\end{cases}
+\end{equation}
+
+\begin{eqnarray}
+\sum_{x,y} z(x,y) T_k(x) T_l(y) & = & \sum_{i,j} P_{i,j} (\delta_{ik} N_x/2 + \delta_{i0} N_x/2) (\delta_{jl} N_y/2 + \delta_{j0} N_y/2) \\
+& = & ( P_{k,l} + P_{k,0} + P_{0,l} + P_{0,0} ) N_x N_y / 4
+\end{eqnarray}
+where $N_x$ and $N_y$ are the order of the polynomials in $x$ and $y$.
+
+Note that this is not a matrix equation, but simply requires a single pass
+through the data to calculate each coefficient.
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 \subsubsection{Polynomials}
+\label{sec:polynomials}
 
 We will employ Chebyshev polynomials (NR \S 5.8) to approximate functions:
