2

I want to solve the following equation for x with SymPy:

formula

(Note that the equation can be simplified as mentioned in the comments, I copied it verbatim from an example in a legal document.)

According to my understanding, this translates to the following SymPy expression:

from sympy import Sum, solve
from sympy.abc import k, x

solve(350 - 18500 + Sum(182.94 * (1/(1+x)**(k/12)), (k, 1, 120)), x)

However, when I run this, the result is empty:

[]

What am I doing wrong?

mrts
  • 16,697
  • 8
  • 89
  • 72
  • 1
    I think you can bring `182.94` in front of the sigma symbol since it does not include `k`. Addition has the following feature: `ax + ay = a(x+y)`. – Eerik Sven Puudist Apr 22 '20 at 10:53
  • You are right, I followed the given example to the letter, without simplifying it. That should not affect SymPy calculation though. – mrts Apr 22 '20 at 11:05

1 Answers1

4

solve probably shouldn't give [] but you will get better results from nsolve for this expression using a guess for x near 0:

>>> from sympy.abc import k, x
>>> from sympy import nsolve
eq = 350 - 18500 + Sum(182.94 * (1/(1+x)**(k/12)), (k, 1, 120))
>>> nsolve(eq, 0)
0.0397546543274819
>>> eq.subs(x,_).round(2)
0
smichr
  • 16,948
  • 2
  • 27
  • 34