How to produce a polynomial trend line equation that takes three arrays as parameters?

Does anyone know of any programming code for producing a polynomial trend line equation that takes three arrays as parameters, ie X, Y and Weight?

Or even if you could explain in English how such a program would work.

-
Generally speaking, the gist of polynomial regression is the same as linear regression (or weighted regression) in that you have to solve for the least squares/maximum likelihood estimates of the coefficients $\hat{\beta}=(X^TWX)^{-1}X^TWY$, except that columns of your matrix $X$ now include polynomial transformations of the original data.
A more complex alternative would be locally weighted regression, which involves fitting the above model, weighted polynomial regression, to each observation. However, the weights $W$ used at each observation are a function of how far the other observations are from the current one. An example of such a function would be the Gaussian kernel.