Ask Your Question
0

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

asked 2017-10-06 01:06:53 +0100

updated 2017-10-10 18:45:39 +0100

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 flag offensive close merge delete

Comments

1

Welcome to Ask Sage!

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?

slelievre gravatar imageslelievre ( 2017-10-06 23:40:29 +0100 )edit

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

mforets gravatar imagemforets ( 2017-10-07 12:10:24 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-10-06 23:10:10 +0100

ndomes gravatar image
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)
edit flag offensive delete link more
1

answered 2017-10-07 20:45:17 +0100

calc314 gravatar image

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
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

1 follower

Stats

Asked: 2017-10-06 01:06:53 +0100

Seen: 272 times

Last updated: Oct 10 '17