Chebyshev coefficients: Difference between revisions

Content added Content deleted
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 691: Line 691:
0.950 0.58168308946388349416 0.58168308946388349403 -1.63e-19</pre>
0.950 0.58168308946388349416 0.58168308946388349403 -1.63e-19</pre>
=={{header|EasyLang}}==
=={{header|EasyLang}}==
<syntaxhighlight lang="text">numfmt 0 5
<syntaxhighlight lang="text">
numfmt 0 5
a = 0
a = 0
b = 1
b = 1
Line 697: Line 698:
len coef[] n
len coef[] n
len cheby[] n
len cheby[] n
for i range n
for i = 0 to n - 1
coef[i] = cos (180 / pi * (cos (180 / n * (i + 1 / 2)) * (b - a) / 2 + (b + a) / 2))
coef[i + 1] = cos (180 / pi * (cos (180 / n * (i + 1 / 2)) * (b - a) / 2 + (b + a) / 2))
.
.
for i range n
for i = 0 to n - 1
w = 0
w = 0
for j range n
for j = 0 to n - 1
w += coef[j] * cos (180 / n * i * (j + 1 / 2))
w += coef[j + 1] * cos (180 / n * i * (j + 1 / 2))
.
.
cheby[i] = w * 2 / n
cheby[i + 1] = w * 2 / n
print cheby[i]
print cheby[i + 1]
.
.</syntaxhighlight>
</syntaxhighlight>

=={{header|Go}}==
=={{header|Go}}==
Wikipedia gives a formula for coefficients in a section [https://en.wikipedia.org/wiki/Chebyshev_polynomials#Example_1 "Example 1"]. Read past the bit about the inner product to where it gives the technique based on the discrete orthogonality condition. The N of the WP formulas is the parameter nNodes in the code here. It is not necessarily the same as n, the number of polynomial coefficients, the parameter nCoeff here.
Wikipedia gives a formula for coefficients in a section [https://en.wikipedia.org/wiki/Chebyshev_polynomials#Example_1 "Example 1"]. Read past the bit about the inner product to where it gives the technique based on the discrete orthogonality condition. The N of the WP formulas is the parameter nNodes in the code here. It is not necessarily the same as n, the number of polynomial coefficients, the parameter nCoeff here.