# Solving a system of equations -- small known number hinders the solution

Hello, I'm trying to solve a system of equations in the treatment of an equilibrium system. I don't get any answers when I use the code below as is.

If I define K = 4.48e-13:

var('x,y,z')
K=4.48e-13
xi=0.75
yi=0
zi=0
eq1=K==y^2*z/x^2
eq2=xi+yi==x+y
eq3=2*xi+yi+2*zi==2*x+y+2*z
solns = solve([eq1,eq2,eq3],x,y,z,solution_dict=True)
[[s[x].n(30), s[y].n(30), s[z].n(30)] for s in solns]


I get:

[]

I do get numbers when I change the known value of "K" in the 2nd line to 4.48e-10 or bigger.

var('x,y,z')
K=4.48e-10
xi=0.75
yi=0
zi=0
eq1=K==y^2*z/x^2
eq2=xi+yi==x+y
eq3=2*xi+yi+2*zi==2*x+y+2*z
solns = solve([eq1,eq2,eq3],x,y,z,solution_dict=True)
[[s[x].n(30), s[y].n(30), s[z].n(30)] for s in solns]


[[0.75039762 - 0.00068968040I, -0.00039762382 + 0.00068968023I, -0.00019881201 + 0.00034484028I], [0.75039762 + 0.00068968040I, -0.00039762382 - 0.00068968023I, -0.00019881201 - 0.00034484028I], [0.74920475, 0.00079524857, 0.00039762445]]

I did not test past 1e-10. I tried increasing the number of bits to 100 for all 3 unknowns with no luck. Is there any way to solve the problem using SageMath using the smaller number? Thanks!

edit retag close merge delete

1

To display inline code, use backticks. To display blocks of code or error messages, separate them by a blank line from the rest of the text, and indent them with 4 spaces, or select code lines and click the "code" button (the icon with '101 010').

For instance, typing

If we define f by

def f(x, y):
return (x, y)

then f(2, 3) returns (2, 3) but f(2) gives:

TypeError: f() takes exactly 2 arguments (1 given)


will produce:

If we define f by

def f(x, y):
return (x, y)


then f(2, 3) returns (2, 3) but f(2) gives:

TypeError: f() takes exactly 2 arguments (1 given)


Can you edit your question to do that?

( 2017-10-06 16:40:29 -0600 )edit

it would be nice to have that info in the help page. i cannot do it, but maybe someone else can do it.

( 2017-10-07 05:10:24 -0600 )edit

Sort by » oldest newest most voted

Here is an approach using Sympy.

from sympy.solvers import solve
from sympy import Symbol
x=Symbol('x')
y=Symbol('y')
z=Symbol('z')

K=4.48e-13
xi=0.75
yi=0
zi=0

eq1=y**2*z/x**2-K
eq2=xi+yi-(x+y)
eq3=2*xi+yi+2*zi-(2*x+y+2*z)

print eq1,eq2,eq3

ans=solve([eq1,eq2,eq3],x,y,z)
print ans

more
var('x,y,z,K')
#K=4.48e-13   # use later for substitution
xi=0.75
yi=0
zi=0
eq1 = K==y^2*z/x^2
eq2 = xi+yi==x+y
eq3 = 2*xi+yi+2*zi==2*x+y+2*z

#  x , y dependent on z
solns = solve([eq2,eq3],x,y)
print solns

# z dependent on K
solns2 = solve(eq1.subs(solns),z)
print solns2

print solns2[2].subs(K=4.48e-13)   # using real solution
solns3 = solve([eq2,eq3.subs(z == 0.0000397877574911779)],x,y)
for s in solns3[0]: print s.lhs() == s.rhs().n(30)

more