# Chebyshev Coefficients for 1/(1+x^2); interpretation of equations in paper

**URL:** <https://discourse.julialang.org/t/chebyshev-coefficients-for-1-1-x-2-interpretation-of-equations-in-paper/66001>\
**Category:** Numerics\
**Created:** [August 7, 2021, 10:20pm UTC](https://discourse.julialang.org/t/chebyshev-coefficients-for-1-1-x-2-interpretation-of-equations-in-paper/66001 "2021-08-07T22:20:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![blackeneth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blackeneth/32/10353_2.png) [@blackeneth](https://discourse.julialang.org/u/blackeneth)\
**Post date:** [August 7, 2021, 10:20pm UTC](https://discourse.julialang.org/t/chebyshev-coefficients-for-1-1-x-2-interpretation-of-equations-in-paper/66001/1 "2021-08-07T22:20:34Z")

</div>

I need to calculate C2k from the paper, _Modification of of Owen’s Method for Computing the Bivariate Normal Integral (DM Borth, 1973)._

The relevant bit of math is here:

 ![borthC2k](https://global.discourse-cdn.com/julialang/original/3X/3/7/370467c3f28c4843feda481fe4ee8ce5f4ce2034.png)

Note the sentence,

Letting\ C\_{2k} \ be\ the\ sum\ of\ the\ coefficients\ of\ x^{2k} \ from\ the\ various\ Chebyshev\ polynomials ...

Later, a table of the coefficients for _m=6_ is given:

![BorthC2kTable](https://global.discourse-cdn.com/julialang/original/3X/9/3/93b58225f1a4234cfd677d9d841478df3d0b6246.png)

So I’ve tried to calculate C2k for _m=6_.

```julia
Using ApproxFun 
cf = Fun(x->1/(1+x^2),Chebyshev())
cx = coefficients(cf)

```

```julia
julia> cx
43-element Vector{Float64}:
  0.7071067811865475
  0.0
 -0.24264068711928516
  0.0
  0.04163056034261582
  0.0
 -0.007142674936409816
  ⋮
  0.0
 -4.036230797029855e-15
  0.0
  6.467742735441352e-16
  0.0
 -9.003474632934613e-17

```

If I try to reproduce the table, I get (note translation from 0 indexing to 1 indexing):

```julia
julia> for k in 0:6;println(k,"\t",cx[2k+1]);end
0 0.7071067811865475
1 -0.24264068711928516
2 0.04163056034261582
3 -0.007142674936409816
4 0.0012254892758431872
5 -0.00021026071864915557
6 3.6075036051548e-5

```

As you see, it does not match!

Any ideas on how I should be computing C2k?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 8, 2021, 12:27am UTC](https://discourse.julialang.org/t/chebyshev-coefficients-for-1-1-x-2-interpretation-of-equations-in-paper/66001/2 "2021-08-08T00:27:30Z")

</div>

The coefficients of the Chebyshev polynomials (what ApproxFun gives you, and the coefficients of S in your equation 9) are not the same as the coefficients of the monic polynomials (your C2k).

Furthermore, it looks like that paper may be using the exact minimax polynomial fit, whereas ApproxFun uses a (very good) approximation thereof. In any case, I would suggest comparing ApproxFun’s coefficients to those of S\_2k in equation (9).

In general, there is no need to compute the coefficients of a polynomial in a monic basis. You can evaluate a polynomial directly from its coefficients in a Chebyshev basis using a Clenshaw recurrence.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [August 8, 2021, 3:07am UTC](https://discourse.julialang.org/t/chebyshev-coefficients-for-1-1-x-2-interpretation-of-equations-in-paper/66001/3 "2021-08-08T03:07:08Z")

</div>

It is possible to compute the monomial expansion from the Chebyshev one if you use high precision (`BigFloat`). Unfortunately I don’t think this is currently implemented in an easy-to-use way, though it wouldn’t be too hard.

---

<div class="post-metadata">

**Author:** ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Post date:** [August 8, 2021, 5:06am UTC](https://discourse.julialang.org/t/chebyshev-coefficients-for-1-1-x-2-interpretation-of-equations-in-paper/66001/4 "2021-08-08T05:06:12Z")

</div>

> [@stevengj](#):
>
> The coefficients of the Chebyshev polynomials (what ApproxFun gives you, and the coefficients of S in your equation 9) are not the same as the coefficients of the monic polynomials (your C2k).
> 
> Furthermore, it looks like that paper may be using the exact minimax polynomial fit, whereas ApproxFun uses a (very good) approximation thereof. In any case, I would suggest comparing ApproxFun’s coefficients to those of S\_2k in equation (9).
> 
> In general, there is no need to compute the coefficients of a polynomial in a monic basis. You can evaluate a polynomial directly from its coefficients in a Chebyshev basis using a Clenshaw recurrence.

I am not sure, but is there a chance you’re mixing the polynomials and the coefficients?  
Namely, and I vaguely remember, Chebyshev Polynomials are the basis and the coefficients define the linear combination.

So in @blackeneth’s problem {S}\_{2K} \left( x \right) are the [Chebyshev Polynomials](https://en.wikipedia.org/wiki/Chebyshev_polynomials) but the code he calculated are the coefficients of {S}\_{2k} \left( x \right) but not itself (As implied from your answer: " and the coefficients of S in your equation 9").

So `ApproxFun` gives the coefficients for Chebyshev Polynomials while his problem his the coefficients of the polynomial of the form {x}^{2k} . In his problem they derive it by expanding the coefficients of {x}^{2k} from the equation 9.

So, in order to get {C}\_{2k} @blackeneth needs to put the definition of Chebyshev Polynomials (Not the coefficients) in (9) and create the form in (10) with some basic algebra (Hopefully).

---

<div class="post-metadata">

**Author:** ![blackeneth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blackeneth/32/10353_2.png) [@blackeneth](https://discourse.julialang.org/u/blackeneth)\
**Post date:** [August 12, 2021, 2:50am UTC](https://discourse.julialang.org/t/chebyshev-coefficients-for-1-1-x-2-interpretation-of-equations-in-paper/66001/5 "2021-08-12T02:50:05Z")

</div>

I don’t “get it” ☹

---

<div class="post-metadata">

**Author:** ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Post date:** [August 12, 2021, 5:21am UTC](https://discourse.julialang.org/t/chebyshev-coefficients-for-1-1-x-2-interpretation-of-equations-in-paper/66001/6 "2021-08-12T05:21:10Z")

</div>

To illustrate simple example, think you have the polynomial basis:

{s}\_{1} \left( x \right) = 2 x, \quad {s}\_{2} \left( x \right) = 4 {x}^{2}

Now you have a polynomial which is:

P \left( x \right) = \sum\_{i = 1}^{2} {\left( ii + 1 \right)}^{2} {s}\_{i} \left( x \right)

You could write:

P \left( x \right) = \sum\_{i = 1}^{2} {c}\_{i} {x}^{i}

Where {c}\_{1} = 8, \; {c}\_{2} = 36 .

This is what happens in your problem essentially.

@mbauman , Do you know why the display mode math doesn’t work?

P. S.  
I figured the math thing. Discourse require Display Mode to be written:

```julia
$$
...LaTeX Code...
$$

```

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [August 12, 2021, 2:04pm UTC](https://discourse.julialang.org/t/chebyshev-coefficients-for-1-1-x-2-interpretation-of-equations-in-paper/66001/7 "2021-08-12T14:04:40Z")

</div>

I’ll leave it to others to discuss the merits of doing this, but these coefficients can found using `Polynomials`:

```julia
using Polynomials
P = ChebyshevT # or Chebyshev in SpecialPolynomials
q = 3 - 2*sqrt(2)
P2m(m) = 8q/(1-q^2) * (1/2 +
                       sum((-1)^k * q^k * Polynomials.basis(P, 2k) for k ∈ 1:m-1) +
                       (-1)^m * q^m/(1-q^2)*Polynomials.basis(P, 2m))

Q2m(m) = convert(Polynomial, P2m(m))

```

```julia
julia> coeffs(Q2m(6))[1:2:end]
7-element Vector{Float64}:
  0.9999936227743424
 -0.9992988806338389
  0.9872975750776766
 -0.9109972523246309
  0.6829098229737781
 -0.33602102198833345
  0.07612251134666158

```
