Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
symbolic derivatives of arctan(x)
#1
the following will print the symbolic derivatives of the arctan function, the derivatives are presented in expanded form
I wanted to programmatically compute the derivatives of the arctan function but no amount of searching the web or asking AI would present a simple solution
so I computed the first 10 derivatives in expanded form using the Maple CAS to see if there was a pattern, then I thought to display only the odd number derivatives
[Image: arctan.png]
it looked similar to the Pascal triangle but was unable to find a relationship
then I searched the web for the numbers in the 9th derivative; 362880,3386880,5080320,1451520,40320
the top hit was https://oeis.org/A131980/internal
the numbers are an exact match for the numbers in the derivatives and they are relatively simple to calculate, I use the Pari implementation

Code: (Select All)

_Title "symbolic derivatives of arctan"

$Console:Only
_Dest _Console
Option _Explicit

Const nderivs = 20
Dim As Long n, k, m
Dim As Double sign
Dim As String denom

For n = 0 To nderivs - 1
denom = "(1+x^2)"
If n > 0 Then
denom = denom + "^" + _Trim$(Str$(n + 1))
End If
If n And 1 Then
sign = -1
Else
sign = 1
End If
m = n \ 2
For k = 0 To m
If k < m Then
If k > 0 And sign > 0 Then
Print "+";
End If
Print sign * t(n, k); "/"; denom; "*x^"; _Trim$(Str$(n - 2 * k));
Else
If k > 0 And sign > 0 Then
Print "+";
End If
Print sign * t(n, k);
End If
sign = -sign
Next
If n And 1 Then
Print "*x/"; denom
Else
Print "/"; denom
End If
Next

Function binomial# (n As Long, k As Long)
Dim As Double c
Dim As Long i
If k < 0 Or k > n Then
binomial = 0
Exit Function
End If
If k = 0 Or k = n Then
binomial = 1
Exit Function
End If
k = _IIf(k <= (n - k), k, (n - k)) ' Take advantage of symmetry
c = 1
For i = 0 To k - 1
c = c * (n - i) / (i + 1)
Next
binomial = c
End Function

Function fact# (n As Long)
If n = 0 Or n = 1 Then
fact = 1
Exit Function
End If
If n = 2 Then
fact = 2
Exit Function
End If
Dim As Double f
Dim As Long i
f = 2
For i = 3 To n
f = f * i
Next
fact = f
End Function

' from the pari implementation, see https://oeis.org/A131980
Function t# (n As Long, k As Long)
Dim As Double b
b = binomial(n + 1, 2 * k + 1)
t = fact(n) * b
End Function
Reply
#2
Code: (Select All)

_Title "numerical derivatives of arctan"

$Console:Only
_Dest _Console
Option _Explicit

Const nderivs = 20
Dim As Long n, k, m
Dim As _Integer64 sign
Dim As Double x, dx, denom

x = 1
Print "the first "; nderivs; " derivatives of arctan(x) at x="; x
For n = 0 To nderivs - 1
    denom = (1 + x ^ 2)
    If n > 0 Then
        denom = denom ^ (n + 1)
    End If
    If n And 1 Then
        sign = -1
    Else
        sign = 1
    End If
    m = n \ 2
    dx = 0
    For k = 0 To m
        dx = dx + sign * t(n, k) / denom * x ^ (n - 2 * k)
        sign = -sign
    Next
    Print "derivative("; n + 1; ") = "; dx
Next

Function binomial# (n As Long, k As Long)
    Dim As Double c
    Dim As Long i
    If k < 0 Or k > n Then
        binomial = 0
        Exit Function
    End If
    If k = 0 Or k = n Then
        binomial = 1
        Exit Function
    End If
    k = _IIf(k <= (n - k), k, (n - k)) ' Take advantage of symmetry
    c = 1
    For i = 0 To k - 1
        c = c * (n - i) / (i + 1)
    Next
    binomial = c
End Function

Function fact# (n As Long)
    If n = 0 Or n = 1 Then
        fact = 1
        Exit Function
    End If
    If n = 2 Then
        fact = 2
        Exit Function
    End If
    Dim As _Integer64 f
    Dim As Long i
    f = 2
    For i = 3 To n
        f = f * i
    Next
    fact = f
End Function

' from the pari implementation, see https://oeis.org/A131980
Function t# (n As Long, k As Long)
    Dim As Double b
    b = binomial(n + 1, 2 * k + 1)
    t = fact(n) * b
End Function

output
the first  10  derivatives of arctan(x) at x= 1
derivative( 1 ) =  .5
derivative( 2 ) = -.5
derivative( 3 ) =  .5
derivative( 4 ) =  0
derivative( 5 ) = -3
derivative( 6 ) =  15
derivative( 7 ) = -45
derivative( 8 ) =  0
derivative( 9 ) =  1260
derivative( 10 ) = -11340
Reply




Users browsing this thread: 2 Guest(s)