Chebyshev coefficients: Difference between revisions
Content added Content deleted
(Chebyshev coefficients en FreeBASIC) |
(Chebyshev coefficients en QBasic) |
||
Line 96: | Line 96: | ||
0.950 0.5816830895 0.5816830895 -8.98e-14 |
0.950 0.5816830895 0.5816830895 -8.98e-14 |
||
</pre> |
</pre> |
||
=={{header|BASIC}}== |
|||
==={{header|QBasic}}=== |
|||
{{works with|QBasic}} |
|||
{{works with|QuickBasic|4.5}} |
|||
{{trans|FreeBASIC}} |
|||
<lang qbasic>pi = 4 * ATN(1) |
|||
a = 0: b = 1: n = 10 |
|||
DIM cheby!(n) |
|||
DIM coef!(n) |
|||
FOR i = 0 TO n - 1 |
|||
coef(i) = COS(COS(pi / n * (i + 1 / 2)) * (b - a) / 2 + (b + a) / 2) |
|||
NEXT i |
|||
FOR i = 0 TO n - 1 |
|||
w = 0 |
|||
FOR j = 0 TO n - 1 |
|||
w = w + coef(j) * COS(pi / n * i * (j + 1 / 2)) |
|||
NEXT j |
|||
cheby(i) = w * 2 / n |
|||
PRINT USING " # : ##.#####################"; i; cheby(i) |
|||
NEXT i |
|||
END</lang> |
|||
{{out}} |
|||
<pre> |
|||
0 : 1.647169470787048000000 |
|||
1 : -0.232299402356147800000 |
|||
2 : -0.053715050220489500000 |
|||
3 : 0.002458173315972090000 |
|||
4 : 0.000282166845863685000 |
|||
5 : -0.000007787576578266453 |
|||
6 : -0.000000536595905487047 |
|||
7 : 0.000000053614126471757 |
|||
8 : 0.000000079823998078155 |
|||
9 : -0.000000070922546058227 |
|||
</pre> |
|||
==={{header|FreeBASIC}}=== |
|||
<lang freebasic>Const pi As Double = 4 * Atn(1) |
|||
Dim As Double i, w, j |
|||
Dim As Double a = 0, b = 1, n = 10 |
|||
Dim As Double cheby(10), coef(10) |
|||
For i = 0 To n-1 |
|||
coef(i) = Cos(Cos(pi/n*(i+1/2))*(b-a)/2+(b+a)/2) |
|||
Next i |
|||
For i = 0 To n-1 |
|||
w = 0 |
|||
For j = 0 To n-1 |
|||
w += coef(j) * Cos(pi/n*i*(j+1/2)) |
|||
Next j |
|||
cheby(i) = w*2/n |
|||
Print i; " : "; cheby(i) |
|||
Next i |
|||
Sleep</lang> |
|||
{{out}} |
|||
<pre> 0 : 1.647169475390314 |
|||
1 : -0.2322993716151719 |
|||
2 : -0.05371511462204768 |
|||
3 : 0.002458235266981634 |
|||
4 : 0.0002821190574339161 |
|||
5 : -7.7222291556156e-006 |
|||
6 : -5.898556451056081e-007 |
|||
7 : 1.152142750093788e-008 |
|||
8 : 6.596299062522348e-010 |
|||
9 : -1.002201654998203e-011</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |
||
Line 586: | Line 657: | ||
print cheby[i] |
print cheby[i] |
||
.</lang> |
.</lang> |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic>Const pi As Double = 4 * Atn(1) |
|||
Dim As Double i, w, j |
|||
Dim As Double a = 0, b = 1, n = 10 |
|||
Dim As Double cheby(10), coef(10) |
|||
For i = 0 To n-1 |
|||
coef(i) = Cos(Cos(pi/n*(i+1/2))*(b-a)/2+(b+a)/2) |
|||
Next i |
|||
For i = 0 To n-1 |
|||
w = 0 |
|||
For j = 0 To n-1 |
|||
w += coef(j) * Cos(pi/n*i*(j+1/2)) |
|||
Next j |
|||
cheby(i) = w*2/n |
|||
Print i; " : "; cheby(i) |
|||
Next i |
|||
Sleep</lang> |
|||
{{out}} |
|||
<pre> 0 : 1.647169475390314 |
|||
1 : -0.2322993716151719 |
|||
2 : -0.05371511462204768 |
|||
3 : 0.002458235266981634 |
|||
4 : 0.0002821190574339161 |
|||
5 : -7.7222291556156e-006 |
|||
6 : -5.898556451056081e-007 |
|||
7 : 1.152142750093788e-008 |
|||
8 : 6.596299062522348e-010 |
|||
9 : -1.002201654998203e-011</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |