Search code examples
pythonsympymaple

system of nonlinear equations can be solved in Maple, but not in sympy


I am new to sympy and enjoyed the pythonic syntax. However, I encountered a problem that can't be solved by sympy but can be easily solved in Maple.

So, I have following system:

0.0165 * exp( -2.0405-0.33*b-0.5*n)+0.031 * exp(-4.164-0.62*b-0.5*n)=k*p
0.025 * exp( -2.0405-0.33*b-0.5*n) +0.025 * exp(-4.164-0.62*b-0.5*n)=5*k
2*p=p*b+5*n

I need to solve b,n and k in terms of p. I can easily solve this in Maple, but using sympy, it takes forever and crashed at the end for exhausting the RAM. Maple can provide exact symbolic solutions.

The sympy code I used is solve([eq1,eq2,eq3],[b,n,k])

Thank for you any help!


Solution

  • Use the rational=False flag:

    >>> print filldedent(solve([eq1,eq2,eq3],[b,n,k], rational=False))
    
    [(-3.44827586206897*log((-0.000335859591913345*p +
    0.00110833665331404)/(2.24927535168052e-5*p - 0.000139455071804192)) +
    2, 0.689655172413793*p*log((-0.000335859591913345*p +
    0.00110833665331404)/(2.24927535168052e-5*p - 0.000139455071804192)),
    (0.000335859591913345*((-0.000335859591913345*p +
    0.00110833665331404)/(2.24927535168052e-5*p -
    0.000139455071804192))**1.13793103448276 +
    2.24927535168052e-5*((-0.000335859591913345*p +
    0.00110833665331404)/(2.24927535168052e-5*p - 0.000139455071804192))**
    2.13793103448276)*exp(-0.344827586206897*p*log((-0.000335859591913345*
    p + 0.00110833665331404)/(2.24927535168052e-5*p -
    0.000139455071804192))))]