Reputation: 17
I am new to python and using the sympy package. However there is an equation with summation that has to be differentiated, and values substituted into it. I was wondering if there are any examples that I can use?
The equation I want to differentiate is the pearson correlation coefficient.
Any inputs will be appreciated.
Upvotes: 0
Views: 38
Reputation: 14500
In [1]: from sympy import *
In [2]: x, i = symbols('x, i')
In [3]: s = Sum(x**2*i, (i, 1, 5))
In [4]: s
Out[4]:
5
___
╲
╲ 2
╱ i⋅x
╱
‾‾‾
i = 1
In [5]: s.diff(x)
Out[5]:
5
___
╲
╲
╱ 2⋅i⋅x
╱
‾‾‾
i = 1
In [6]: s.diff(x).subs(x, 3)
Out[6]:
5
___
╲
╲
╱ 6⋅i
╱
‾‾‾
i = 1
In [7]: s.diff(x).subs(x, 3).doit()
Out[7]: 90
Upvotes: 1