
Software: 
Suppose we have a onevariable function f(x)
whose values are known at points which may be unevenly spaced:
N_{x} where the A_{i}'s are constants and N_{x}+1 is the number of terms in x. For an exact fit, N_{x}=P_{x}, otherwise N_{x}<P_{x}. If we use x_{C} as center of expansion, the approximating function's value at the m_{th} grid point is: N_{x} To do an exact fit, at each grid point we equate the value of the function at that grid point to the value of the approximation at the same grid point:
N_{x} This way we set up a system of linear equations from which the coefficients A_{i} can be easily found. If we have a 2variable tabulated function f(x,y) whose values are known at the grid points of a rectangular grid which may be unevenly spaced, such as
which has P_{x} intervals in the xdirection and P_{y} intervals in the ydirection, we can approximate the function by a linear combination of the first N_{x}+1 and N_{y}+1 members of certain complete sets of functions {G_{i}} and {H_{j}} using a series expansion of the form: N_{x}
N_{y} which has N_{x}+1 terms in x and N_{y}+1 terms in y. For an exact fit, N_{x}=P_{x} and N_{y}=P_{y}, otherwise N_{x}<P_{x} and/or N_{y}<P_{y}. If we use (x_{C},y_{C}) as center of expansion, the approximating function's value at the (x_{m},y_{n}) grid point is: N_{x}
N_{y} To do an exact fit, at each grid point we equate the value of the function at that grid point to the value of the approximation at the same grid point:
N_{x}
N_{y} This way we set up a system of linear equations from which the coefficients A_{ij }can be easily found. Extension to more than 2 variables is obvious. The sets of functions used here, that is, {G_{i}} and {H_{j}}, are: 1, (xx_{C}), (xx_{C})^{2}, (xx_{C})^{3}, (xx_{C})^{4},... and 2p(xx_{C})
2p(xx_{C})
2*2p(xx_{C})
2*2p(xx_{C}) where x_{C } is the center of expansion and PER is the period. The use of finite power and trigonometric series is partly justified by Weierstrass' Approximation Theorems: 1) Any function which is continuous in an interval may be approximated in that interval, to any degree of accuracy, by a finite power series. 2) Any continuous periodic function may be approximated, to any degree of accuracy, by a finite trigonometric series. Naturally, if the function itself is not a finite power or trigonometric series, then we need more and more terms for more and more accuracy. A power or trigonometric series with infinite number of terms may yield the exact value of the function, as is the case with Taylor and Fourier series. Developing a Fourier or Taylor series, however, may not be very easy. A Fourier series requires the evaluation of the Fourier Coefficients, which are integrals which in turn may need numerical evaluation. A Taylor expansion requires you to find all the function's derivatives and this may be a difficult task. (Curiously, continuous nondifferentiable functions exist, that is, there are continuous curves with no tangent at any point.) Thus, the Weierstrass' Theorems make this approach acceptable if the solution is known to be continuous in the interval of interest. If necessary, the problem should be solved piecewise, each time choosing an interval in which the solution and its derivatives are known to be continuous and sufficiently smooth (with a limited number of wiggles). 

Copyright © 20012010 Numerical Mathematics. All rights reserved.
