Você está na página 1de 11

>> chebyshev_polynomial_test

25-Apr-2012 08:38:35
CHEBYSHEV_POLYNOMIAL_TEST:
MATLAB version.
Test the CHEBYSHEV_POLYNOMIAL library.
CHEBYSHEV_POLYNOMIAL_TEST01:
T_PROJECT_COEFFICIENTS_DATA estimates the Chebyshev polynomial
coefficients for a function given as data (x,fx).
Here, we use fx = f(x) = x^2 for the data.
Since T(0,x) = 1 and T(2,x) = 2*x^2 - 1, the correct expansion is
f(x) = 1/2 T(0,x) + 0 T(1,x) + 1/2 T(2,x) + 0 * all other polys.
Data ( X, D ):
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:

0.218418
0.956318
0.829509
0.561695
0.415307
0.0661187
0.257578
0.109957
0.043829
0.633966
0.0617272
0.449539
0.401306
0.754673
0.797287
0.00183837
0.897504
0.350752
0.0945448
0.0136169

0.0477066
0.914543
0.688086
0.315502
0.17248
0.00437169
0.0663463
0.0120905
0.00192098
0.401913
0.00381025
0.202085
0.161047
0.569532
0.635666
3.37961e-06
0.805514
0.123027
0.00893871
0.00018542

Coefficients of Chebyshev expansion of degree 4.

1:
0.5
2: -1.00619e-14
3:
0.5
4: -2.96699e-15
I
1
2
3
4
5
6
7
8
9
10
11
12

X(I)
0.218418
0.956318
0.829509
0.561695
0.415307
0.0661187
0.257578
0.109957
0.043829
0.633966
0.0617272
0.449539

Data(I)
0.0477066
0.914543
0.688086
0.315502
0.17248
0.00437169
0.0663463
0.0120905
0.00192098
0.401913
0.00381025
0.202085

Chebyshev(X(I))
0.0477066
0.914543
0.688086
0.315502
0.17248
0.00437169
0.0663463
0.0120905
0.00192098
0.401913
0.00381025
0.202085

13
14
15
16
17
18
19
20

0.401306
0.754673
0.797287
0.00183837
0.897504
0.350752
0.0945448
0.0136169

0.161047
0.569532
0.635666
3.37961e-06
0.805514
0.123027
0.00893871
0.00018542

0.161047
0.569532
0.635666
3.37961e-06
0.805514
0.123027
0.00893871
0.00018542

CHEBYSHEV_POLYNOMIAL_TEST02
T_POLYNOMIAL_COEFFICIENTS determines the Chebyshev
polynomial coefficients.
T(0,x) =
1.000000
T(1,x) =
1.000000 * x
T(2,x) =
2.000000 * x^2
-1.000000
T(3,x) =
4.000000 * x^3
-3.000000 * x
T(4,x) =
8.000000 * x^4
-8.000000 * x^2
1.000000
T(5,x) =
16.000000 * x^5
-20.000000 * x^3
5.000000 * x
CHEBYSHEV_POLYNOMIAL_TEST03:
T_POLYNOMIAL_VALUES stores values of
the Chebyshev polynomials.
T_POLYNOMIAL evaluates the polynomial.
N

Tabulated
T(n,x)

Computed
T(n,x)

rror
0

0.800000

1.0000000000000000e+00

1.0000000000000000e+00

0.800000

8.0000000000000004e-01

8.0000000000000004e-01

0.800000

2.8000000000000003e-01

2.8000000000000025e-01 -2.2e-

0.800000

-3.5199999999999998e-01

-3.5199999999999965e-01 -3.3e-

0
0
16
16

0.800000

-8.4319999999999995e-01

-8.4319999999999973e-01 -2.2e-

0.800000

-9.9712000000000001e-01

-9.9712000000000001e-01

0.800000

-7.5219199999999997e-01

-7.5219200000000042e-01

4.4e-

0.800000

-2.0638719999999999e-01

-2.0638720000000066e-01

6.7e-

0.800000

4.2197247999999998e-01

4.2197247999999932e-01

6.7e-

0.800000

8.8154316799999999e-01

8.8154316799999966e-01

3.3e-

10

0.800000

9.8849658880000002e-01

9.8849658880000013e-01 -1.1e-

11

0.800000

7.0005137409999996e-01

7.0005137408000073e-01

12

0.800000

1.3158560969999999e-01

1.3158560972800104e-01 -2.8e-

16
0
16
16
16
16
16
2e-

11
11
CHEBYSHEV_POLYNOMIAL_TEST04:
T_POLYNOMIAL_ZEROS computes the zeros of T(n,x);
N

T(n,x)

0.0000

6.12323e-17

1
2

0.7071
-0.7071

2.22045e-16
-2.22045e-16

1
2
3

0.8660
0.0000
-0.8660

3.33067e-16
-1.83697e-16
-3.33067e-16

1
2
3
4

0.9239
0.3827
-0.3827
-0.9239

-2.22045e-16
-2.22045e-16
1.11022e-16
-2.22045e-16

1
2
3
4
5

0.9511
0.5878
0.0000
-0.5878
-0.9511

-4.44089e-16
0
3.06162e-16
-7.77156e-16
4.44089e-16

CHEBYSHEV_POLYNOMIAL_TEST05:
associated with T(n,x);
X

W
1:
2:
3:
4:
5:
6:
7:

-0.974928
-0.781831
-0.433884
2.19909e-16
0.433884
0.781831
0.974928

0.448799
0.448799
0.448799
0.448799
0.448799
0.448799
0.448799

Q = Integral ( -1 <= X <= +1 ) X^E / sqrt ( 1-x^2) dx

E
0
1
2
3
4
5
6
7
8
9
10
11
12
13

Q_Estimate
3.14159
-5.55112e-17
1.5708
-1.11022e-16
1.1781
-5.55112e-17
0.981748
5.55112e-17
0.859029
1.11022e-16
0.773126
2.22045e-16
0.708699
3.33067e-16

Q_Exact
3.14159
0
1.5708
0
1.1781
0
0.981748
0
0.859029
0
0.773126
0
0.708699
0

CHEBYSHEV_POLYNOMIAL_TEST06:
As a sanity check, make sure that the projection of:
T(i,x) onto T(j,x) is:
0 if i is not equal to j;
pi if i = j = 0;
pi/2 if i = j =/= 0.
Chebyshev expansion coefficients for T(0,x)
1:
3.14159
2: 7.21645e-16
3: -5.55112e-16
4: -4.44089e-16
Chebyshev expansion coefficients for T(1,x)
1: 7.21645e-16
2:
1.5708
3: 2.22045e-16
4: 3.33067e-16
Chebyshev expansion coefficients for T(2,x)
1: -5.55112e-16
2: 1.11022e-16
3:
1.5708
4: 6.66134e-16
Chebyshev expansion coefficients for T(3,x)
1: -4.44089e-16
2: 3.33067e-16
3: 6.10623e-16
4:
1.5708
CHEBYSHEV_POLYNOMIAL_TEST07:
T_PROJECT_COEFFICIENTS computes the Chebyshev coefficients
of a function defined over [-1,+1].
T_PROJECT_COEFFICIENTS_AB works in [A,B].
Chebyshev coefficients for exp(x) in [-1,+1]

1:
2:
3:
4:

1.26607
1.13031
0.27145
0.0437939

Chebyshev coefficients for exp(x) in [-1,+1]

1:
1.26607
2:
1.13032
3:
0.271495
4:
0.0443368
5: 0.00547404
6: 0.000539728
Chebyshev coefficients for sin(x) in [-1,+1]
1: 1.85037e-17
2:
0.880101
3: 1.11022e-16
4: -0.0391267
5: 2.77556e-16
6: 0.00050252
Chebyshev coefficients for sin(x) in [-1,+1]
1: 1.85037e-17
2:
0.880101
3: 1.11022e-16
4: -0.0391267
5: 3.14563e-16
6: 0.00050252
Chebyshev coefficients for sqrt(x) in [0,+1]
1:
2:
3:
4:
5:
6:

0.638441
0.420681
-0.0808705
0.0318506
-0.01484
0.00614694

CHEBYSHEV_POLYNOMIAL_TEST08:
T_PROJECT_COEFFICIENTS_DATA computes the Chebyshev
coefficients of a function defined by data.
We are looking for an approximation that is good in [-1,+1].
Begin by using equally spaced points in [-1,+1].
Chebyshev coefficients for exp(x) on [-1,+1]
1:
2:
3:
4:

1.26667
1.13052
0.271785
0.0443939

Chebyshev coefficients for exp(x) on [-1,+1]

1:

1.26608

2:
1.13032
3:
0.271515
4:
0.0443381
5: 0.00547599
6: 0.000542394
Chebyshev coefficients for sin(x) on [-1,+1]
1:
2:
3:
4:
5:
6:

5.12815e-17
0.880099
-3.47596e-17
-0.0391279
-1.45253e-17
0.000500014

Now sample equally spaced points in [0,+1].

The approximation still applies to the interval [-1,+1].
Chebyshev coefficients for sin(x) on [0,+1]
1: 0.000726991
2:
0.878798
3: 0.000930442
4: -0.0396401
5: 0.00020353
6: 0.000452446
Chebyshev coefficients for sqrt(x) on [0,+1]
1:
2:
3:
4:
5:
6:

-14.6903
26.9799
-17.4287
8.41285
-2.73608
0.463969

Now random points in [-1,+1].

Chebyshev coefficients for sin(x) on [-1,+1]
1:
2:
3:
4:
5:
6:

-2.30327e-07
0.880106
-8.76709e-07
-0.0391223
2.87075e-09
0.000503295

CHEBYSHEV_POLYNOMIAL_TEST09:
T_PROJECT_COEFFICIENTS computes the Chebyshev interpolant C(F)(N,X)
of a function F(X) defined over [-1,+1].
T_PROJECT_VALUE evaluates that projection.
Compute projections of order N to exp(x) over [-1,+1],
N
0
1
2
3

Max||F(X)-C(F)(N,X)||
1.718
0.3722
0.05647
0.006657

4
5
6
7
8
9
10

0.0006397
5.18e-05
3.62e-06
2.224e-07
1.219e-08
6.027e-10
2.714e-11

CHEBYSHEV_POLYNOMIAL_TEST10:
T_PROJECT_COEFFICIENTS_AB computes the Chebyshev interpolant C(F)(N,X)
of a function F(X) defined over [A,B].
T_PROJECT_VALUE_AB evaluates that projection.
Compute projections of order N to exp(x) over [0.000000, 1.500000],
N
0
1
2
3
4
5
6
7
8
9
10

Max||F(X)-C(F)(N,X)||
2.365
0.3967
0.04629
0.004159
0.0003031
1.855e-05
9.786e-07
4.532e-08
1.87e-09
6.956e-11
2.354e-12

CHEBYSHEV_POLYNOMIAL_TEST11
U_POLYNOMIAL_COEFFICIENTS determines the
polynomial coefficients for U(n,x).
U(0,x) =
1.000000
U(1,x) =
2.000000 * x
U(2,x) =
4.000000 * x^2
-1.000000
U(3,x) =
8.000000 * x^3
-4.000000 * x
U(4,x) =
16.000000 * x^4
-12.000000 * x^2
1.000000
U(5,x) =
32.000000 * x^5

-32.000000 * x^3
6.000000 * x
CHEBYSHEV_POLYNOMIAL_TEST12:
U_POLYNOMIAL_VALUES stores values of
the Chebyshev polynomials U(n,x).
U_POLYNOMIAL evaluates the polynomial.
N

Tabulated
U(n,x)

Computed
U(n,x)

rror
0

0.800000

1.0000000000000000e+00

1.0000000000000000e+00

0.800000

1.6000000000000001e+00

1.6000000000000001e+00

0.800000

1.5600000000000001e+00

1.5600000000000005e+00 -4.4e-

0.800000

8.9600000000000002e-01

8.9600000000000080e-01 -7.8e-

0.800000

-1.2640000000000001e-01

-1.2639999999999918e-01 -8.3e-

0.800000

-1.0982400000000001e+00

-1.0982399999999994e+00 -6.7e-

0.800000

-1.6307840000000000e+00

-1.6307840000000000e+00

0.800000

-1.5110144000000001e+00

-1.5110144000000008e+00

6.7e-

0.800000

-7.8683904000000005e-01

-7.8683904000000138e-01

1.3e-

0.800000

2.5207193600000000e-01

2.5207193599999855e-01

1.4e-

10

0.800000

1.1901541376000000e+00

1.1901541375999991e+00

8.9e-

11

0.800000

1.6521746841600000e+00

1.6521746841600000e+00

12

0.800000

1.4533253570560001e+00

1.4533253570560012e+00 -1.1e-

0
0
16
16
16
16
0
16
15
15
16
0
15
CHEBYSHEV_POLYNOMIAL_TEST13:
T_POLYNOMIAL_ZEROS computes the zeros of U(n,x);
N

U(n,x)

0.0000

1.22465e-16

1
2

0.5000
-0.5000

4.44089e-16
-8.88178e-16

1
2
3

0.7071
0.0000
-0.7071

6.66134e-16
-2.44929e-16
6.66134e-16

1
2
3
4

0.8090
0.3090
-0.3090
-0.8090

0
-1.11022e-16
5.55112e-16
-8.88178e-16

1
2

0.8660
0.5000

1.33227e-15
-8.88178e-16

3
4
5

0.0000
-0.5000
-0.8660

3.67394e-16
-1.77636e-15
-1.33227e-15

CHEBYSHEV_POLYNOMIAL_TEST14:
associated with U(n,x);
X

W
1:
2:
3:
4:
5:
6:
7:

-0.92388
-0.707107
-0.382683
7.90193e-18
0.382683
0.707107
0.92388

0.0575094
0.19635
0.33519
0.392699
0.33519
0.19635
0.0575094

Use the quadrature rule to estimate:

Q = Integral ( -1 <= X <= +1 ) X^E * sqrt ( 1-x^2) dx
E

Q_Estimate

0
1
2
3
4
5
6
7
8
9
10
11
12
13

1.5708
5.55112e-17
0.392699
-5.55112e-17
0.19635
-1.249e-16
0.122718
-1.66533e-16
0.0859029
-1.73472e-16
0.0644272
-1.80411e-16
0.0506214
-1.76942e-16

Q_Exact
1.5708
0
0.392699
0
0.19635
0
0.122718
0
0.0859029
0
0.0644272
0
0.0506214
0

CHEBYSHEV_POLYNOMIAL_TEST15:
V_POLYNOMIAL_VALUES stores values of
the Chebyshev polynomials.
V_POLYNOMIAL evaluates the polynomial.
N

Tabulated
V(n,x)

Computed
V(n,x)

rror
0

0.800000

1.0000000000000000e+00

1.0000000000000000e+00

0.800000

5.9999999999999998e-01

6.0000000000000009e-01 -1.1e-

0.800000

-4.0000000000000001e-02

-3.9999999999999813e-02 -1.9e-

0.800000

-6.6400000000000003e-01

-6.6399999999999981e-01 -2.2e-

0.800000

-1.0224000000000000e+00

-1.0224000000000000e+00

0.800000

-9.7184000000000004e-01

-9.7184000000000015e-01

0
16
16
16
0
16

1.1e-

0.800000

-5.3254400000000002e-01

-5.3254400000000035e-01

3.3e-

0.800000

1.1976960000000000e-01

1.1976959999999959e-01

4.2e-

0.800000

7.2417536000000005e-01

7.2417535999999971e-01

3.3e-

0.800000

1.0389109759999999e+00

1.0389109759999999e+00

10

0.800000

9.3808220160000000e-01

9.3808220160000022e-01 -2.2e-

11

0.800000

4.6202054656000002e-01

4.6202054656000047e-01 -4.4e-

12

0.800000

-1.9884932710400000e-01

-1.9884932710399938e-01 -6.1e-

16
16
16
0
16
16
16
CHEBYSHEV_POLYNOMIAL_TEST16:
W_POLYNOMIAL_VALUES stores values of
the Chebyshev polynomials.
W_POLYNOMIAL evaluates the polynomial.
N

Tabulated
W(n,x)

Computed
W(n,x)

rror
0

0.800000

1.0000000000000000e+00

1.0000000000000000e+00

0.800000

2.6000000000000001e+00

2.6000000000000001e+00

0.800000

3.1600000000000001e+00

3.1600000000000001e+00

0.800000

2.4560000000000000e+00

2.4560000000000008e+00 -8.9e-

0.800000

7.6959999999999995e-01

7.6960000000000139e-01 -1.4e-

0.800000

-1.2246400000000000e+00

-1.2246399999999986e+00 -1.3e-

0.800000

-2.7290239999999999e+00

-2.7290239999999990e+00 -8.9e-

0.800000

-3.1417983999999999e+00

-3.1417984000000003e+00

4.4e-

0.800000

-2.2978534399999999e+00

-2.2978534400000017e+00

1.8e-

0.800000

-5.3476710400000005e-01

-5.3476710400000238e-01

2.3e-

10

0.800000

1.4422260736000001e+00

1.4422260735999979e+00

2.2e-

11

0.800000

2.8423288217599998e+00

2.8423288217599989e+00

8.9e-

12

0.800000

3.1055000412160001e+00

3.1055000412160005e+00 -4.4e-

0
0
0
16
15
15
16
16
15
15
15
16
16
CHEBYSHEV_POLYNOMIAL_TEST17:
T_TRIPLE_PRODUCT_INTEGRAL computes the triple integral
Tijk = integral ( -1 <= x <= 1 ) T(i,x) T(j,x) T(k,x) / sqrt ( 1-x^2) dx
I

3
4

3
2

4
0

Tijk
computed

Tijk
exact
0
0

-6.27276e-15
-4.60743e-15

3
5
4
2
2
6
3
3
5
4
2
2
5
5
6
5
5
5

1
1
3
3
1
1
3
3
2
3
3
2
2
1
3
1
1
3

0
2
3
1
4
0
0
1
4
2
1
1
1
1
0
3
4
2

0
0
0
0.785398
0
0
1.5708
0
0
0
0.785398
0
0
0
0
0
0.785398
0.785398

CHEBYSHEV_POLYNOMIAL_TEST:
Normal end of execution.
25-Apr-2012 08:38:35
>>

-4.2466e-15
-5.55112e-15
-6.27276e-15
0.785398
-3.91354e-15
-6.68909e-15
1.5708
-2.7478e-15
-4.38538e-15
-3.21965e-15
0.785398
-1.77636e-15
-5.55112e-15
-5.66214e-15
-4.02456e-15
-3.66374e-15
0.785398
0.785398