Ask Your Question
1

Problem solving a system of equations

asked 2018-02-20 11:52:13 +0100

CrisSanz gravatar image

updated 2018-02-20 22:09:52 +0100

tmonteil gravatar image

Hello everyone,

Here I copy my code in sage.

var('r2 si co r12 r22 r32 d32')

eq1 = r12==r2*d32*(1-si*(co+sqrt(3*(1-co*co)))/2)/2

eq2 = r22==r2*d32*(1-si*(co-sqrt(3*(1-co*co)))/2)/2

eq3 = r32==r2*d32*(1+si*co)/2

eq1.show()

eq2.show()

eq3.show()

solve([eq1,eq2,eq3],r2,si,co)


And this is the answer that I get when I execute:

Error in lines 1-1
Traceback (most recent call last):
  File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
  File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 1050, in solve
    sol_list = string_to_list_of_solutions(repr(s))
  File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 580, in string_to_list_of_solutions
    v = symbolic_expression_from_maxima_string(s, equals_sub=True)
  File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/calculus/calculus.py", line 2159, in symbolic_expression_from_maxima_string
    raise TypeError("unable to make sense of Maxima expression '%s' in Sage"%s)
TypeError: unable to make sense of Maxima expression '[if((-pi/2<parg(-((3*_SAGE_VAR_r22-3*_SAGE_VAR_r12)*sqrt(_SAGE_VAR_r32^2+((-_SAGE_VAR_r22)-_SAGE_VAR_r12)*_SAGE_VAR_r32+_SAGE_VAR_r22^2-_SAGE_VAR_r12*_SAGE_VAR_r22+_SAGE_VAR_r12^2))/(2*_SAGE_VAR_r32^2+((-2*_SAGE_VAR_r22)-2*_SAGE_VAR_r12)*_SAGE_VAR_r32+2*_SAGE_VAR_r22^2-2*_SAGE_VAR_r12*_SAGE_VAR_r22+2*_SAGE_VAR_r12^2)))and(parg(-((3*_SAGE_VAR_r22-3*_SAGE_VAR_r12)*sqrt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*_SAGE_VAR_r32+2*_SAGE_VAR_r22^2-2*_SAGE_VAR_r12*_SAGE_VAR_r22+2*_SAGE_VAR_r12^2)))and(parg(((3*_SAGE_VAR_r22-3*_SAGE_VAR_r12)*sqrt(_SAGE_VAR_r32^2+((-_SAGE_VAR_r22)-_SAGE_VAR_r12)*_SAGE_VAR_r32+_SAGE_VAR_r22^2-_SAGE_VAR_r12*_SAGE_VAR_r22+_SAGE_VAR_r12^2))/(2*_SAGE_VAR_r32^2+((-2*_SAGE_VAR_r22)-2*_SAGE_VAR_r12)*_SAGE_VAR_r32+2*_SAGE_VAR_r22^2-2*_SAGE_VAR_r12*_SAGE_VAR_r22+2*_SAGE_VAR_r12^2))<==pi/2),[_SAGE_VAR_co==((2*_SAGE_VAR_r32-_SAGE_VAR_r22-_SAGE_VAR_r12)*sqrt(_SAGE_VAR_r32^2+((-_SAGE_VAR_r22)-_SAGE_VAR_r12)*_SAGE_VAR_r32+_SAGE_VAR_r22^2-_SAGE_VAR_r12*_SAGE_VAR_r22+_SAGE_VAR_r12^2))/(2*_SAGE_VAR_r32^2+((-2*_SAGE_VAR_r22)-2*_SAGE_VAR_r12)*_SAGE_VAR_r32+2*_SAGE_VAR_r22^2-2*_SAGE_VAR_r12*_SAGE_VAR_r22+2*_SAGE_VAR_r12^2),_SAGE_VAR_r2==(2*_SAGE_VAR_r32+2*_SAGE_VAR_r22+2*_SAGE_VAR_r12)/(3*_SAGE_VAR_d32),_SAGE_VAR_si==(2*sqrt(_SAGE_VAR_r32^2+((-_SAGE_VAR_r22)-_SAGE_VAR_r12)*_SAGE_VAR_r32+_SAGE_VAR_r22^2-_SAGE_VAR_r12*_SAGE_VAR_r22+_SAGE_VAR_r12^2))/(_SAGE_VAR_r32+_SAGE_VAR_r22+_SAGE_VAR_r12)],union())]' in Sage


​
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2018-02-20 23:34:32 +0100

tmonteil gravatar image

updated 2018-02-20 23:34:54 +0100

This seems to be a bug, apparently due to the fact that Sage is not able to deal with what is returned by maxima (this might be related to the fat that the returned solution has conditions (if...)) . Thanks for reporting, this is now trac ticket 24800.

Note that sympy is not able to solve it either:

sage: solve([eq1,eq2,eq3],r2,si,co, algorithm='sympy') 
NotImplementedError: could not solve 4*r22 - (si*(-sqrt(3 - 27*(-2*r32 - (12*r12 + 12*r32 - 4*sqrt(3)*sqrt(r12**2*si**2 - r12**2 + r12*r32*si**2 + 2*r12*r32 + r32**2*si**2 - r32**2))/(3*(si**2 - 4)))**2*(si**2 - 4)**2/(si**2*(12*r12 + 12*r32 - 4*sqrt(3)*sqrt(r12**2*si**2 - r12**2 + r12*r32*si**2 + 2*r12*r32 + r32**2*si**2 - r32**2))**2)) + 3*(-2*r32 - (12*r12 + 12*r32 - 4*sqrt(3)*sqrt(r12**2*si**2 - r12**2 + r12*r32*si**2 + 2*r12*r32 + r32**2*si**2 - r32**2))/(3*(si**2 - 4)))*(si**2 - 4)/(si*(12*r12 + 12*r32 - 4*sqrt(3)*sqrt(r12**2*si**2 - r12**2 + r12*r32*si**2 + 2*r12*r32 + r32**2*si**2 - r32**2)))) - 2)*(12*r12 + 12*r32 - 4*sqrt(3)*sqrt(r12**2*si**2 - r12**2 + r12*r32*si**2 + 2*r12*r32 + r32**2*si**2 - r32**2))/(3*(si**2 - 4))

That said, you can easily get rid of the square roots by hand, then solve the new equations, and keep among the solutions the one for which what was under the square roots is non-negative.

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: 2018-02-20 11:52:13 +0100

Seen: 229 times

Last updated: Feb 20 '18