After having tried many things, I thought it would be good to ask on SO. My problem is fairly simple: how can I solve the following equation using Sympy?
I want to solve this for lambda_0 and q
is an array of size J
containing elments between 0 and 1 that sum op to 1 (discrete probability distribution). I tried the following:
from sympy.solvers import solve
from sympy import symbols, summation
p = [0.2, 0.3, 0.3, 0.1, 0.1]
l = symbols('l')
j = symbols('j')
eq= summation(j*q[j]/(l-j), (j, 0, 4))
s= solve(eq, l)
But this gives me an error for q[j]
as j
is a Symbol
object here and not an integer. If I don't make j
as symbol, I cannot evaluate the eq
expression. Does anyone know how to do this?
Edit: p = 1-q
in the above, hence q[j]
should have been replaced by (1-p[j])
.