Ask Your Question
0

Make sage to don't open brackets while solving equation

asked 2011-06-01 12:28:33 +0100

avi9526 gravatar image

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)

get answer

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?

(sorry for bad eng.)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2011-06-01 13:38:52 +0100

DSM gravatar image

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.

edit flag offensive delete link more

Comments

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

avi9526 gravatar imageavi9526 ( 2011-06-01 14:36:33 +0100 )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.

DSM gravatar imageDSM ( 2011-06-01 14:50:44 +0100 )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

avi9526 gravatar imageavi9526 ( 2011-06-02 14:10:15 +0100 )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.

DSM gravatar imageDSM ( 2011-06-02 14:19:20 +0100 )edit

I use, 4.6.2, seems some problems

avi9526 gravatar imageavi9526 ( 2011-06-03 11:54:13 +0100 )edit
1

answered 2011-06-01 13:05:42 +0100

Juanlu001 gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-06-01 12:28:33 +0100

Seen: 1,114 times

Last updated: Jun 01 '11