Shyam
Shyam

Reputation: 17

Is there a way to use SymPy to solve this problem?

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

Answers (1)

Oscar Benjamin
Oscar Benjamin

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

Related Questions