Function Tn(n,x)

Copper Contributor

I have defined the function:
Function Tn (n, x)
     Tn = Cos (n * Acos (x))
End Function
But there is a problem. For all values of n and x (-1: 1) the value of Tn (n, x) is always "ZERO".
If I calculate Cos (x), n * Acos (x) and Cos (n * Acos (x)) separately then the result is correct.

Where is my mistake.

3 Replies
i would recommend reposting this in one of the Excel groups so that you can get help from people that have expertise with that application

Good day.

I could not solve the problem of the Tn (n, x) function. I only changed the function name from Tn to Tc.
But I solved the problem with another method.
Here is the solution that I recommend. It has been checked for many values of n and x [-1: 1] and works correctly.

Function Tc (n, x)

     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 This is n
             T = 2 * x * S - R
             R = S
             S = T
         Next and
         Tc = T
     End Select

End Function

Best Regards

Hello.
Maybe this is not a topic for this Forum, but that I do charts in Excel. I thought I could post it here. I enclose 2 PDFs to illustrate the problem. Intuition suggests that the Scs function should be monotonically decreasing (without the maximum), but it is different. Where do I make a mistake ????