How to transform function values to specific interval

2.5k Views Asked by At

I'm doing a project at university about scientific computing and I'm stuck. As in: I seem to lack quite a bit of mathematical background for this project.

The program has as input an array of $x$ values and their corresponding $f(x)$ values. We're supposed to approximate $f(x)$ by using a basis of polynomials:

A basis with which we can approximate $f(x)$ consists of polynomials $p_n(x)$ that are orthonormal in $[-1, 1]$ with respect to the weight function $w(x)=(1-x)^\alpha(1+x)^\beta$ with $\alpha, \beta > -1$. Here, $n$ is the degree of the polynomial and the following holds $$\int_{-1}^1 w(x)p_n(x)p_k(x)dx = 0, \quad k \neq n \quad (1)$$ $$\int_{-1}^1 w(x)p_n(x)^2dx = 1. \quad\quad\quad\quad\quad\quad (2)$$ You can set up this basis using Gram-Schmidt orthogonalisation. In this, we start from the zeroth degree Lagrange polynomial, and in every step we start from the Lagrange polynomial of degree $n$ with $n > + 1$ interpolation points at equal distance in $[-1, 1]$ (corner points included) and which is (for example) always 1 in the highest interpolation point and 0 on the other ones. We make this orthogonal with respect to all previous ones (1) and then, it is normalised (2).

For most of this stuff I was able to google how this is done. So the above is mainly background I guess. Don't know if you'll need it to answer my question. Anyway, my question concerns the following remark:

Also remark that the approximation interval is $x \in [-1, 1]$ here. If the data you have about $f(x)$ concern another interval, you have to transform $f(x)$ to $[-1, 1]$.

The data I have does have $x$-points outside $[-1, 1]$ (and their corresponding $f(x)$ values). But I have no idea how this transformation would work.

So could anyone explain to me how this transformation would work? Even pointing me in the right way with specific terms I can google on would be helpful...

1

There are 1 best solutions below

3
On BEST ANSWER

Suppse your data points are, in increasing order, $x_0,x_1,\dotsc,x_n$. Then the simplest way to map these to $[-1,1]$ is to do a linear transformation, which simply amounts to a rescaling and a shift. You have several possibilities to do this:

  1. If your data are bounded in absolute value by some number $a$, you can just divide by $a$, because $$ -a \leqslant x_i \leqslant a \implies -1 \leqslant \frac{x_i}{a} \leqslant 1 $$ (obviously you should choose $a$ to be computationally sensible: presumably the next power of $2$ would be reasonable).
  2. Another possibility is to make the data take up as much of $[-1,1]$ as possible, perhaps for computational accuracy or something (or they're all centred around a point a long way from the origin, so would end up with errors), then you can take $$ \frac{2}{x_n-x_0}\left(x_i - \frac{x_0+x_n}{2}\right) $$ for each $i=0,1,\dotsc,n$: obviously this preserves the order of the $x_i$, and putting in $x_0$ and $x_n$ gives $-1$ and $1$ respectively.
  3. Or you can combine the two approaches, if you know the points are less than a distance $a$ from a value $b$, and take $(x_i-b)/a$.

This is really the only sensible way to do it, since other maps, even if invertible, may change the order of the points or the relative distances between them. Linear transformations avoid this.


Now, the functions. Let $f(x_i)=y_i$, and let the transformation you have chosen be $T$, which maps $x_i$ to $z_i \in [-1,1]$. Define $g = f \circ {T^{-1}}$, from which we have $$ g(z_i) = f(T^{-1}(z_i)) = f(x_i) = y_i. $$ Now, $g$ is a function defined on $[-1,1]$, so we can use the procedure you mention to create a polynomial approximation to it, $p(z)$. $p$'s argument $z$ still lives in $[-1,1]$, hence we need to turn it back into an argument $x$ that lives in the same space as the original $x_i$. The way to do this is apply the inverse of $T$, so that $x=T^{-1}z$ (as with the $x_i$ and $z_i$ earlier).

The final answer is then that $p \circ T^{-1}$ is a polynomial approximation to $f$: $p(T^{-1}(x))=p(z)$. So the upshot is that you compose $p$ with the inverse of the transformation you originally used.

(It's easier to think in terms of spaces: if $f:A \to B$, and $[-1,1]=C$, and you have a map $T:A\to C$ and a polynomial approximation of $g: C \to B$, then an approximation of $f=g \circ T^{-1}:A \to B$ needs to be made by composing with $T^{-1}$ so that your variable lives in $A$ rather than $C$.)