# Function SUMA problem

Highlighted
Occasional Contributor

# Function SUMA problem

Hi!
I have a problem with the SUMA_Ai_Tci function. An argument error is returned when the function is called. (the compiler does not indicate an error)
The Tc function works correctly.

I am asking for a hint as to how to find a mistake.

Option Explicit

Function SUMA_Ai_Tci (n As Byte, x As Double, Ai) As Double

'The function calculates the sum of the coefficient products
'Ai (i) and Chebyshev polynomial of the order i [A (i) * Tc (i, x)]
'for -1 <=x <=1.

Dim i, j As Byte
Dim S As Double

S = 0 #

For i = 1 To n
S = S + Ai (i) * Tc (i, x)
ActiveCell.Range ("A1"). Select
ActiveCell.FormulaR1C1 = S
ActiveCell.Range ("A2"). Select
Next i

SUMA_Ai_Tci = S

End Function 'SUMA

Function Tc (n, x)
'
'The Tc function calculates the orthogonal value
'Chebyshev polynomial of order n for -1 <= x <= 1
'
Dim and As Byte
Dim R, S, T As Double

Select Case n
Case Is = 0
Tc = 1

Case Is = 1
Tc = x

Case Is> 1
R = 1
S = x
For i = 2 To n
T = 2 * x * S - R
R = S
S = T
Next i
Tc = T
End Select

End Function 'Tc

0 Replies