switching from solve to solveset

45 views
Skip to first unread message

Jon Durand

unread,
Jan 28, 2019, 3:47:52 AM1/28/19
to sympy
Hello,

I'm a fairly novice python user who had lightly brushed up against sympy a few years ago and understood a bit of the original solve.
Lately I've been trying to write code for solving functions I use and would use a dictionary of symbol, value pairs and would solve things like this:
solve( eq.subs(dictionary))

I recently noticed the existence of solveset and the notice to use it over solve, so I am trying to convert my code to use solveset but I can't seem to find the information
on how to substitute values into equations that are going into the solver. I imagine this is easy and I'm missing something simple but I've googled and read through a bunch of sympy doc pages and couldn't find the relevant part for solveset.

Any help is greatly appreciated, thank you for your time.

Yathartha Joshi

unread,
Jan 28, 2019, 7:45:15 AM1/28/19
to sympy
Hey Jon,

I assume you want to do something like this:

>>> eq = x**2 - y
>>> solve(eq.subs({y:1}))
[-1, 1]

You can achieve this with `solveset` too:

>>> solveset(eq.subs({y:1}))
{-1, 1}

Primarily `solve` and `solveset` differs in the way they return output, the former uses `list` while the latter uses `set`.

Below links, you might find helpful for getting along with `solveset`

https://docs.sympy.org/latest/modules/solvers/solveset.html
Yathartha
Reply all
Reply to author
Forward
0 new messages