>>> import numpy
>>> from sympy import *
>>> x = symbols("x")
>>> y = symbols("y")
>>> a = symbols("a")
>>> f = a*x + y
>>> solve([x + 5*y - 2, -3*x + 6*y -15], [x, y])
{x: -3, y: 1}
>>> print f
a*x + y
das hab ich ins python shell geschrieben - ist also gut und schön, aber...
hast einer ne idee, wie ich das hinkriege, dass direkt auf die lösung zugegriffen wird, da also nach print f das stehen würde:
-3*a + 1
und nicht a*x + y
Weiterverwendung der Lösung eines Gleichungssystems
-
BlackJack
Code: Alles auswählen
In [7]: f
Out[7]: y + a*x
In [8]: r = {x: -3, y: 1}
In [9]: f(r)
Out[9]: 1 - 3*a-
BlackJack
Also bei mir ist das `Add`-Objekt aufrufbar:
Code: Alles auswählen
In [226]: type(f)
Out[226]: <class 'sympy.core.add.Add'>
In [227]: f(r)
Out[227]: 1 - 3*a
In [228]: sympy.__version__
Out[228]: '0.6.6'