Ask Your Question
1

Any way to solve these simultaneous equations using Sage?

asked 2017-01-04 03:05:25 +0200

omoplata gravatar image

updated 2023-01-09 23:59:40 +0200

tmonteil gravatar image

Input is as following

   1: var('E_0,E,gamma,c,v,m,m_0')
(E_0, E, gamma, c, v, m, m_0)
   2: eq1 = gamma == 1/sqrt(1-v^2/c^2)
   3: eq2 = m == gamma*m_0
   4: eq3 = E == m*c^2
   5: eq4 = E_0 == m_0*c^2
   6: solve([eq1,eq2,eq3,eq4],v,m,m_0,gamma)

The expected solution for v is v = c * sqrt(1-E_0^2/E^2).

I get the following error message. I tried assuming all the variables to be positive and real, but get the same error message.

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-6-c0343319abfc> in <module>()
----> 1 solve([eq1,eq2,eq3,eq4],v,m,m_0,gamma)

/home/sage/sage-7.4/local/lib/python2.7/site-packages/sage/symbolic/relation.pyc in solve(f, *args, **kwds)
    863             s = []
    864 
--> 865     sol_list = string_to_list_of_solutions(repr(s))
    866 
    867     # Relaxed form suggested by Mike Hansen (#8553):

/home/sage/sage-7.4/local/lib/python2.7/site-packages/sage/symbolic/relation.pyc in string_to_list_of_solutions(s)
    538     from sage.structure.sequence import Sequence
    539     from sage.calculus.calculus import symbolic_expression_from_maxima_string
--> 540     v = symbolic_expression_from_maxima_string(s, equals_sub=True)
    541     return Sequence(v, universe=Objects(), cr_str=True)
    542 

/home/sage/sage-7.4/local/lib/python2.7/site-packages/sage/calculus/calculus.pyc in symbolic_expression_from_maxima_string(x, equals_sub, maxima)
   1798     if len(x) == 0:
   1799         raise RuntimeError("invalid symbolic expression -- ''")
-> 1800     maxima.set('_tmp_',x)
   1801 
   1802     # This is inefficient since it so rarely is needed:

/home/sage/sage-7.4/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc in set(self, var, value)
    504             raise TypeError
    505         cmd = '%s : %s$'%(var, value.rstrip(';'))
--> 506         self.eval(cmd)
    507 
    508     def clear(self, var):

/home/sage/sage-7.4/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc in _eval_line(self, line, locals, reformat, **kwds)
    450                 line = line[ind_dollar+1:]
    451                 if statement:
--> 452                     maxima_eval("#$%s$" % statement)
    453         if not reformat:
    454             return result

/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__call__ (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:7698)()
    793 
    794         """
--> 795         lispargs = EclObject(list(args))
    796         return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))
    797 

/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__init__ (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:7221)()
    658         """
    659         if len(args) != 0:
--> 660             self.set_obj(python_to_ecl(args[0]))
    661 
    662     def __reduce__(self):

/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.python_to_ecl (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:6254)()
    473             return Cnil
    474         else:
--> 475             L=cl_cons(python_to_ecl(pyobj[0]),Cnil)
    476             ptr=L
    477             for a in pyobj[1:]:

/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.python_to_ecl (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:5990)()
    457     elif isinstance(pyobj,bytes):
    458         s=<bytes>pyobj
--> 459         return ecl_safe_read_string(s)
    460     elif isinstance(pyobj,Integer):
    461         if pyobj >= MOST_NEGATIVE_FIXNUM and pyobj <= MOST_POSITIVE_FIXNUM:

/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_read_string (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:5409)()
    374     cdef cl_object o
    375     o = ecl_cstring_to_base_string_or_nil(s)
--> 376     o = ecl_safe_funcall(read_from_string_clobj,o)
    377     return o
    378 

/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_funcall (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:5208)()
    355     if ecl_nvalues > 1:
    356         s = si_coerce_to_base_string(ecl_values(1))
--> 357         raise RuntimeError("ECL says: "+ecl_base_string_pointer_safe(s))
    358     else:
    359         return ecl_values(0)

RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-01-04 16:20:25 +0200

tmonteil gravatar image

updated 2017-01-04 16:34:21 +0200

You can use sympy:

sage: import sympy
sage: sympy.var('E_0,E,gamma,c,v,m,m_0')
(E_0, E, gamma, c, v, m, m_0)
sage: sympy.solve([gamma - 1/sqrt(1-v^2/c^2), m - gamma*m_0, E - m*c^2, E_0 - m_0*c^2], v,m,m_0,gamma)
[(-c*sqrt(1 - E_0**2/E**2), E/c**2, E_0/c**2, E/E_0),
 (c*sqrt(1 - E_0**2/E**2), E/c**2, E_0/c**2, E/E_0)]

Or, you can add asumptions on Sage symbols:

sage: var('E_0,E,gamma,c,v,m,m_0')
(E_0, E, gamma, c, v, m, m_0)
sage: assume(gamma > 0, m > 0, m_0 > 0, c > 0, E > 0, E_0 > 0)
sage: eq1 = gamma == 1/sqrt(1-v^2/c^2)
sage: eq2 = m == gamma*m_0
sage: eq3 = E == m*c^2
sage: eq4 = E_0 == m_0*c^2
sage: solve([eq1,eq2,eq3,eq4],v,m,m_0,gamma)
[[gamma == E/E_0, m == E/c^2, m_0 == E_0/c^2, v == -sqrt(E^2 - E_0^2)*c/E], [gamma == E/E_0, m == E/c^2, m_0 == E_0/c^2, v == sqrt(E^2 - E_0^2)*c/E]]
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-01-04 03:05:25 +0200

Seen: 414 times

Last updated: Jan 04 '17