首页 > 解决方案 > SymPy : Using Results of sympy.solve function

问题描述

I will try to use the result of solve function in sympy

from sympy import solve,  expand,

SolutionForPi = (alpha*mu*(-gamma*l*rho + gamma*l - gamma*pi*rho + gamma*pi - l*rho - pi*rho)/(-rho/(rho - 1) + 1) + f*mu)-pi
SolutionForPi = solve(SolutionForPi, pi)

The Result is

[mu*(-alpha*gamma*l*rho**2 + 2*alpha*gamma*l*rho - alpha*gamma*l - alpha*l*rho**2 + alpha*l*rho - f)/(alpha*gamma*mu*rho**2 - 2*alpha*gamma*mu*rho + alpha*gamma*mu + alpha*mu*rho**2 - alpha*mu*rho - 1)]

Then I use sympy.expend function

ExpandSolution = expand(SolutionForPi)

But I get this error :

AttributeError: 'list' object has no attribute 'expand'

What I understand is this is a list not an equation so what should I do ?

标签: pythonpython-3.xsympy

解决方案


如果您的解决方案封装在列表中,请访问(单个)列表成员

ExpandSolution = expand(SolutionForPi[0])

推荐阅读