Sage solve returns empty list

asked 2017-12-20 11:24:23 +0100

Bobesh gravatar image

I have very complex formula, and I have to solve that formula for one of variables (get some variable from expression). If I use solve() function is sage, it returns empty list, which is odd, but I found that it could be caused by too complex expression. So I managed to use sympy.solve(), but it returns exception. Here is part of my code:

 k, u, v ,w , E, B, S, J, C1, C2 = var('k', 'u', 'v', 'w', 'E', 'B', 'S', 'J', 'C1', 'C2')
#assumptions
assume(B > 0)
assume(S > 0)
assume(J > 0)
assume(k > 0)
assume((u*E^2 + v*E + w) > 0)

f1 = (S == 1/6*(4*E^3*u + 3*E^2*v)/B + 1/6*(2*E^3*u + 3*E^2*v + 6*E*w)/B - k)
f2 = (J == E/B - k/(E^2*u + E*v + w))

#solve f1 and f2 for E

E_S = solve(f1, E)
E_J = solve(f2, E)

#under our assumptions only E_S[2] and A_J[2] are real
#so for that solutions lets find S

f_S1 = (E_S[2].right() == E_J[2].right())

#show(f_S1)

solve(f_S1, S) #returns []

import sympy
sympy.solve(f_S1, S) #returns exception

I tried to rewrite to sympy in spyder as well, but computations didint finish in two days so I canceled it.

edit retag flag offensive close merge delete

Comments

It seems that your equation is polynomial, is that right? If you so, you should be using Gröbner basis directly. The solve command does not do that.

vdelecroix gravatar imagevdelecroix ( 2017-12-20 11:27:50 +0100 )edit

I turned the equations f1, f2 into definitions for S, J. Then it seems that we have to solve the equation S==J. So let us factor the difference:

k, u, v ,w , E, B, S, J = var('k', 'u', 'v', 'w', 'E', 'B', 'S', 'J')

S = 1/6*(4*E^3*u + 3*E^2*v)/B + 1/6*(2*E^3*u + 3*E^2*v + 6*E*w)/B - k
S = S.factor()
print S

J = E/B - k/(E^2*u + E*v + w)
J = J.factor()
print J

print (S-J).factor()

This gives:

(E^3*u + E^2*v - B*k + E*w)/B
(E^3*u + E^2*v - B*k + E*w)/((E^2*u + E*v + w)*B)
(E^3*u + E^2*v - B*k + E*w)*(E^2*u + E*v + w - 1)/((E^2*u + E*v + w)*B ...
(more)
dan_fulea gravatar imagedan_fulea ( 2017-12-21 02:10:16 +0100 )edit