How can I find a polynomial that approximates |x|

  • Thread starter happybear
  • Start date
  • Tags
    Polynomial
In summary: Legendre polynomials that converge to f in the L^2 norm (mean square). I'm not sure if the two plots are supposed to be correlated or not, I just drew them to illustrate my point. In summary, according to Stone Weierstrass Theorem, there exists a polynomial such that lim P = |x|. Can anyone give me an example of P? Maybe within the range of 0.01?
  • #1
happybear
19
0

Homework Statement



According to Stone Weierstrass Theorem, there exists a polynomial such that lim P = |x|.
Can anyone give me an example of P? Maybe within the range of 0.01?
ie. |f-P|< 0.01


Homework Equations





The Attempt at a Solution

 
Physics news on Phys.org
  • #2
I'm not sure but I think the Legendre polynomial expansion for |x| would converge uniformly to |x| as stated by Stone-Weierstrass.
 
  • #3
I think it converges in the mean. Since the Legendre polynomials are orthogonal, then we can write:

[tex]f(x)=a_0 P_0(x)+a_1 P_1(x)+a_2 P_2(x)+\cdots[/tex]

with:

[tex]a_k=\frac{2k+1}{2}\int_{-1}^{1} f(x)P_k(x)dx[/tex]

I'd try say 25 of them programatically (in Mathematica) then compare it to [tex]f(x)=|x|[/tex] happybear.
 
  • #4
The important facts are that the Legendre polynomials are both orthogonal and complete. This means that the mean square of the difference between f and the first n terms in the series goes to zero as n → ∞, i.e. the series converges uniformly to f.

EDIT: Turns out this is not true. Read jbunniii's post #8.
 
Last edited:
  • #5
happybear said:
According to Stone Weierstrass Theorem, there exists a polynomial such that lim P = |x|.
Can anyone give me an example of P? Maybe within the range of 0.01?
ie. |f-P|< 0.01
In the interest of making correct statements, what you mean is that there is a sequence of polynomials {Pn} such that limn -> inf Pn(x) = |x| uniformly in x. (Or... maybe you just mean that it converges at each value of x)
 
  • #6
dx said:
The important facts are that the Legendre polynomials are both orthogonal and complete. This means that the mean square of the difference between f and the first n terms in the series goes to zero as n → ∞, i.e. the series converges uniformly to f.

Mean square convergence does not imply uniform convergence in general!

Consider f_n(x) (for n = 1,2,...) defined on [0,1] as an isosceles triangle whose base is the interval [0,1/n] and whose height is 1. If f(x) = 0 on [0,1] then f_n converges to f in the mean square sense (and also pointwise) but the convergence is not uniform.

Maybe it's true that you can find a sequence of Legendre polynomials that converge uniformly to |x| (I'm not sure one way or the other) but if so, this fact isn't implied by mean square convergence.

P.S. I don't think anyone mentioned it yet, but Stone-Weierstrass applies only on a compact set, so it only applies for f(x) = |x| if you restrict the domain.

P.P.S. The Bernstein polynomials were "used by Bernstein in a constructive proof for the Stone-Weierstrass approximation theorem." -- see http://en.wikipedia.org/wiki/Bernstein_polynomial
 
Last edited:
  • #7
The functions in your example are not orthogonal. I could be wrong, but I remember reading somewhere that orthogonality and completeness imply uniform convergence.
 
  • #8
dx said:
The functions in your example are not orthogonal. I could be wrong, but I remember reading somewhere that orthogonality and completeness imply uniform convergence.

Orthogonality and completeness imply L^2 convergence (mean-squared) but not in general L^infinity convergence (uniform). L^2 is special because it is a Hilbert space, whereas L^p is not a Hilbert space if p is not 2.

As I said, I'm not sure whether a sequence of Legendre polynomials that converges to f in L^2 will also converge uniformly. (I haven't found any statements or proofs to that effect after a fair amount of Googling.) But the orthogonality/L^2 convergence alone are not enough to guarantee this.

By the way, there's a very similar situation with Fourier series: the complex exponentials are an orthonormal basis for L^2 and their linear combinations are dense in L^2. For any function f in L^2, its Fourier series converges to f in the L^2 norm (mean-squared sense).

However, there exist even continuous functions whose Fourier series (the partial sums of which are trigonometric polynomials) don't converge at every point (the best you can hope for is pointwise convergence except on a set of measure 0), let alone converge uniformly.

You CAN find a sequence of trigonometric polynomials that do converge uniformly to f if it's continuous [this is in fact also guaranteed by the Stone-Weierstrass theorem if you use a sufficiently general version], but you have to construct them using Fejer sums instead of the "raw" Fourier series.

This is analogous to the situation with Stone-Weierstrass and polynomials - there certainly exist uniformly approximating polynomials to any continuous function on a compact set, but just because you find a sequence of polynomials (orthonormal ones, even) that converges in some other sense (pointwise or L^2) doesn't mean that particular sequence converges uniformly.
 
Last edited:
  • #9
squidsoft said:
I think it converges in the mean. Since the Legendre polynomials are orthogonal, then we can write:

[tex]f(x)=a_0 P_0(x)+a_1 P_1(x)+a_2 P_2(x)+\cdots[/tex]

with:

[tex]a_k=\frac{2k+1}{2}\int_{-1}^{1} f(x)P_k(x)dx[/tex]

I'd try say 25 of them programatically (in Mathematica) then compare it to [tex]f(x)=|x|[/tex] happybear.

Sorry if I caused some awkwardness with the convergence question above, something I barely understand myself. I just want to post some empirical results cus' I'm curious. The plot below is the actual function and a plot of the first 25 terms of the Legendre expansion created with this Mathematica code:

Code:
f[x_] := Abs[x]; 
clist = Table[((2*n + 1)/2)*
     Integrate[f[x]*LegendreP[n, x], 
      {x, -1, 1}], {n, 0, 25}]; 
g[x_] := Sum[clist[[n]]*LegendreP[n - 1, 
      x], {n, 1, 26}]; 
Plot[{f[x], g[x]}, {x, -1, 1}]
 

Attachments

  • afile.jpg
    afile.jpg
    7.5 KB · Views: 535

1. Can I use any degree polynomial to approximate |x|?

Yes, you can use any degree polynomial to approximate |x|, but the higher the degree, the closer the approximation will be to the actual function.

2. How do I determine the coefficients of the polynomial?

The coefficients of the polynomial can be determined by using the method of least squares. This involves minimizing the sum of the squared differences between the polynomial and the actual function at various points.

3. What is the best way to choose the points to use for the approximation?

The best way to choose the points is to evenly distribute them over the range of x values, with a higher concentration of points near the origin. This will ensure a more accurate approximation.

4. Can I use different methods besides least squares to find the coefficients?

Yes, there are other methods such as using the Taylor series expansion or using numerical integration techniques, but the method of least squares is the most commonly used and reliable method for finding the coefficients.

5. How do I know if my polynomial is a good approximation of |x|?

You can determine the accuracy of your polynomial by comparing it to the actual function at various points. The smaller the difference between the polynomial and the function, the better the approximation. Additionally, you can also calculate the root mean square error (RMSE) to measure the overall accuracy of the approximation.

Similar threads

  • Calculus and Beyond Homework Help
Replies
9
Views
1K
  • Calculus and Beyond Homework Help
Replies
7
Views
691
  • Calculus and Beyond Homework Help
Replies
7
Views
1K
  • Calculus and Beyond Homework Help
Replies
2
Views
345
  • Calculus and Beyond Homework Help
Replies
3
Views
914
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
2
Views
837
  • Calculus and Beyond Homework Help
Replies
12
Views
2K
  • Calculus and Beyond Homework Help
Replies
5
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
1K
Back
Top