Forum Discussion

Zbigniew Jachimowicz's avatar
Zbigniew Jachimowicz
Copper Contributor
Aug 28, 2018

Function Tn(n,x)

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.

  • 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

    • Zbigniew Jachimowicz's avatar
      Zbigniew Jachimowicz
      Copper Contributor

      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 ????

  • Dean_Gross's avatar
    Dean_Gross
    Silver Contributor
    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

Resources