ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 20 Dec 2017 19:10:16 -0600Sage solve returns empty listhttp://ask.sagemath.org/question/40250/sage-solve-returns-empty-list/ 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.
Wed, 20 Dec 2017 04:24:23 -0600http://ask.sagemath.org/question/40250/sage-solve-returns-empty-list/Comment by dan_fulea for <p>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:</p>
<pre><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
</code></pre>
<p>I tried to rewrite to sympy in spyder as well, but computations didint finish in two days so I canceled it. </p>
http://ask.sagemath.org/question/40250/sage-solve-returns-empty-list/?comment=40265#post-id-40265I 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)
In case of `S==J` we have thus either $S=0$, or `(E^2*u + E*v + w - 1) == 0`.
What is now the mathematical problem, from this point of view?Wed, 20 Dec 2017 19:10:16 -0600http://ask.sagemath.org/question/40250/sage-solve-returns-empty-list/?comment=40265#post-id-40265Comment by vdelecroix for <p>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:</p>
<pre><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
</code></pre>
<p>I tried to rewrite to sympy in spyder as well, but computations didint finish in two days so I canceled it. </p>
http://ask.sagemath.org/question/40250/sage-solve-returns-empty-list/?comment=40251#post-id-40251It 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.Wed, 20 Dec 2017 04:27:50 -0600http://ask.sagemath.org/question/40250/sage-solve-returns-empty-list/?comment=40251#post-id-40251