# Make sage to don't open brackets while solving equation

Hi, I have an equation

import sympy


...

eq1 = 80*X*e^(T*p) + X*e^(2*T*p) == 5*e^(T*p)/(e^(T*p) - 1) + e^(T*p)/(e^(T*p) - e^(2*T))


and when I do

Xi = eq1.solve(X)
X = Xi[0].right()
X = X.simplify_full()
X = sympy.simplify(X)
X = X.subs(e^(p*T), z)
X = SR(X)


X = (6*z - 5*e^(2*T) - 1)/(z^3 - z^2*e^(2*T) + 79*z^2 - 79*z*e^(2*T) - 80*z + 80*e^(2*T))


Next I need to find pole of X (z that gives denominator==0). But sagemath opened the brackets in denominator

sage: Xi
[X == -(6*e^(T*p) - 5*e^(2*T) - 1)/(79*e^(T*p + 2*T) + e^(2*T*p + 2*T) + 80*e^(T*p) - 79*e^(2*T*p) - e^(3*T*p) - 80*e^(2*T))]


it's very bad. Here numerator have only 3rd power, but if it will be bigger, sagemath (i think) give me no solution. When I do prevision commands using pen and paper I get in denominator

(z-1)*(z+80)*(z-e^(2*T))


how to get it with sagemath?

edit retag close merge delete

Sort by » oldest newest most voted

I'm confused. If I do exactly what you've done above:

sage: reset()
sage: import sympy
sage: var("X T p z")
(X, T, p, z)
sage:
sage: eq1 = 80*X*e^(T*p) + X*e^(2*T*p) == 5*e^(T*p)/(e^(T*p) - 1) + e^(T*p)/(e^(T*p) - e^(2*T))
sage: Xi = eq1.solve(X)
sage: X = Xi[0].right()
sage: X = X.simplify_full()
sage: X = sympy.simplify(X)
sage: X = X.subs(e^(p*T), z)
sage: X = SR(X)
sage:
sage: solve(X.denominator(), z)
[z == e^(2*T), z == -80, z == 1]
sage: factor(X.denominator())
(z - 1)*(z + 80)*(z - e^(2*T))


I seem to get the answers you want.

more

As You can see in my post, I also get this result, but X.denominator() = z^3 - z^2*e^(2*T) + 79*z^2 - 79*z*e^(2*T) - 80*z + 80*e^(2*T), if it will have greater power - sagemath will fail, because its expand branches! if You try do it on paper, You can get (z - 1)*(z + 80)*(z - e^(2*T)) without trying to solve cubic equation

( 2011-06-01 14:36:33 +0200 )edit

Could you give a concrete example of something that fails, and what you wanted to see instead? Then we can try to figure out a way to get Sage to behave.

( 2011-06-01 14:50:44 +0200 )edit

check out this code reset() import sympy var("X T p z a") (X, T, p, z) eq1 = 80*X*z + X*z^2 == z/(z - 1) + z/(z-1*I+2) + z/(z+0.2^0.3) + z/(z+e^(a+2)) + z/(z-12) + z/(z+2*I) Xi = eq1.solve(X) X = Xi[0].right() X = X.simplify_full() solve(X.denominator(), z) # I halt this code because its not responding for 2 min, its can be easy done using pen&paper

( 2011-06-02 14:10:15 +0200 )edit

What version of Sage are you running? I get [z == -1/2*sqrt(-12*I - 5) - 1/2*I - 1, z == 1/2*sqrt(-12*I - 5) - 1/2*I - 1, z == -e^(a + 2), z == 12, z == (-4173/6763), z == -80, z == 1] as output.

( 2011-06-02 14:19:20 +0200 )edit

I use, 4.6.2, seems some problems

( 2011-06-03 11:54:13 +0200 )edit

Your example is a bit messy, but I suggest you to try combine() and denominator() functions:

more