Hi,
Very new to Sympy. Hoping to generate a Sum of an indexed expression, then form a simple expression, and then take derivatives. Finally, I'd like to output the solution using codegen. I'm really struggling. I suspect my use of Sum and or indexed expressions is wrong. All help really appreciated:
import sympy as sm
# would prefer to use the first one of these
#Ns = sm.symbols('Ns', cls=sm.Idx) # gives IndexError: tuple index out of range
Ns = 10 # gives FIXME: No specialized handling of type <class 'sympy.concrete.summations.Sum'>
sp = sm.Idx('sp', Ns)
S = sm.IndexedBase('S')[sp]
total = sm.Sum(S, sp)
# construct simple expression
func = sm.log(S/total)
print(func)
# derivative of Sum
d_total = total.diff(S)
print(d_total)
# derivative of expression
d_func = func.diff(S)
print(d_func)
# print
from sympy.utilities.codegen import codegen
codegen( [("func", func), ("dfunc", d_func)], language="C", prefix="test", to_files=True, header=False, empty=False)