Ask Your Question

omoplata's profile - activity

2023-06-26 22:26:26 +0200 received badge  Famous Question (source)
2022-01-29 18:15:16 +0200 received badge  Notable Question (source)
2022-01-29 18:15:16 +0200 received badge  Popular Question (source)
2021-12-31 22:39:41 +0200 received badge  Notable Question (source)
2021-12-31 19:09:53 +0200 received badge  Popular Question (source)
2021-11-09 17:00:42 +0200 received badge  Famous Question (source)
2020-05-02 09:08:12 +0200 received badge  Notable Question (source)
2020-04-02 23:24:30 +0200 received badge  Famous Question (source)
2019-07-17 13:19:01 +0200 received badge  Popular Question (source)
2019-07-17 13:19:01 +0200 received badge  Notable Question (source)
2019-05-13 21:50:45 +0200 received badge  Notable Question (source)
2019-05-13 21:50:45 +0200 received badge  Popular Question (source)
2019-05-13 21:50:45 +0200 received badge  Famous Question (source)
2019-03-18 09:43:49 +0200 received badge  Popular Question (source)
2018-02-27 11:04:55 +0200 received badge  Notable Question (source)
2017-01-05 02:28:10 +0200 received badge  Nice Answer (source)
2017-01-04 03:05:25 +0200 asked a question Any way to solve these simultaneous equations using Sage?

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.
2017-01-01 21:41:12 +0200 received badge  Self-Learner (source)
2017-01-01 21:41:12 +0200 received badge  Teacher (source)
2017-01-01 18:26:22 +0200 answered a question How to copy code from Jupyter notebook

OK, I found out that this can be done using the %history magic function. For example,

%history -n -o 12-17

prints the inputs 12 to 17 with output, and I can copy from that. But the error messages don't get printed.

2016-12-30 19:21:35 +0200 received badge  Nice Question (source)
2016-12-29 20:52:50 +0200 asked a question How to copy code from Jupyter notebook

How do I copy code from a Jupyter notebook to paste it here? I cannot figure out a way to do it.

In the old sage notebook format you can get a text version of your code input output by clicking a 'text' button that is to the right of the 'worksheet' button. I find that very convenient when posting questions here.

But since Sage seems to be moving to the Jupyter notebook format from the old notebook format, I figured I better get used to the Jupyter notebook.

I'm running Sage in Virtualbox in Windows.

Thank you.

2016-12-29 20:22:46 +0200 answered a question Sage 7.3 jupyter notebook not showing on VM

Right Ctrl F7 works for me.

2016-12-29 20:15:36 +0200 asked a question Any way to solve this differential equation?
sage: x(t)=function('x')(t)
sage: x
t |--> x(t)
sage: g(v,c)=1/sqrt(1-v^2/c^2)
sage: g
(v, c) |--> 1/sqrt(-v^2/c^2 + 1)
sage: var('a')
a
sage: ode = g(diff(x,t))*diff(x,t) == a*t
sage: ode
t |--> diff(x(t), t)/sqrt(-diff(x(t), t)^2/c^2 + 1) == a*t
sage: desolve(ode,x)
Traceback (most recent call last):
...
ValueError: Unable to determine independent variable, please specify.
sage: desolve(ode,[x,t])
Traceback (most recent call last):
...
NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.
sage: desolve(ode,[x,t],contrib_ode=True)
Traceback (most recent call last):
...
NotImplementedError: Maxima was unable to solve this ODE.

I can solve it by hand.

Mathematica can solve it. But I would very much prefer to learn to use Sage because it's open source.

It looks like it is Maxima that cannot solve it. But is it possible to make Sage invoke any other open source program than Maxima? Or use some trick in defining the problem that would allow Maxima to solve it?

Thank you.

2016-12-29 04:14:59 +0200 commented answer How to open jupyter in virtualbox from shared folder?

Thank you. This helped me.

2016-12-28 20:39:07 +0200 commented answer Variable overrites function defined previously

Thanks for clarifying.

But I wasn't TRYING to make a function and variable with the same name. My point is that a beginning user who is unfamiliar with Sage could easily overwrite the function he previously defined with a variable. If this possible cause for error was covered, this is one subtlety that one does not have keep in mind while learning Sage.

2016-12-28 00:00:46 +0200 received badge  Editor (source)
2016-12-27 23:58:06 +0200 asked a question Variable overrites function defined previously

I have u(t) which is an function of t, and g(u) which is a function of u. I want to find the derivative of g(u)*u(t) w.r.t. t.

sage: u(t) = function('u')(t)
sage: h(u) = function('h')(u)
sage: u
u
sage: h
u |--> h(u)
diff(h(u)*u(t),t)
h(u)

This seems to happen because the function u is overwritten when I use u to define the function h. I can get around it this way.

sage: u(t) = function('u')(t)
sage: h(x) = function('h')(x)
sage: u
t |--> u(t)
sage: h
x |--> h(x)
sage: diff(h(u)*u(t),t)
u(t)*D[0](h)(u(t))*D[0](u)(t) + h(u(t))*D[0](u)(t)

Can this be classified as a bug? If it is, would it be possible to fix it?

Thanks in advance.

2016-12-27 20:24:49 +0200 commented answer Why use symbolic functions?

Thanks. I noted also noted that I can declare the variables I need inside the parentheses on the left hand side. For example, I can define,

sage:  x(b,c,t) = sqrt(b^2 + c^2*t^2) - b

without declaring b,c and t to be variables beforehand. But it appears that sage defines these variables in the background while defining the function x(t). So, afterwards, I can input

a

and not get an error, because it appears to have been defined in the background. But inputting a hitherto unused value, such as y, will give an error. Also, if I did not put b and c within parentheses on the left hand side without declaring them beforehand, that would also be an error.

2016-12-25 01:05:00 +0200 received badge  Nice Question (source)
2016-12-24 20:44:49 +0200 asked a question Why use symbolic functions?

So, I can do the following by introducing x as a symbolic function.

sage: var('b,c,t')
(b, c, t)
sage: x(t) = sqrt(b^2 + c^2*t^2) - b
sage: x
t |--> -b + sqrt(c^2*t^2 + b^2)
sage: diff(x,t)
t |--> c^2*t/sqrt(c^2*t^2 + b^2)

I can introduce x as a variable with assigned symbolic values, and get the same result.

sage: var('b,c,t')
(b, c, t)
sage: x = sqrt(b^2 + c^2*t^2) - b
sage: x
-b + sqrt(c^2*t^2 + b^2)
sage: diff(x,t)
c^2*t/sqrt(c^2*t^2 + b^2)

So, since I can do the same thing using variables, why use symbolic functions at all? Can symbolic functions do things that variables can't do?

Thanks in advance.

2016-12-24 20:22:26 +0200 received badge  Notable Question (source)
2016-09-19 22:57:21 +0200 received badge  Good Question (source)
2016-07-26 15:00:27 +0200 received badge  Nice Question (source)
2015-04-28 00:41:23 +0200 received badge  Popular Question (source)
2015-03-27 04:11:57 +0200 marked best answer How can I clear an assignment to a variable?

If I assign a symbolic expression to a variable, how do I clear the assignment as if I didn't assign anything to it in the first place?

For example,

sage: var('a,b')
(a, b)
sage: x=a+b
sage: x
a + b
sage: var(x)
a + b
sage: x
a + b
sage: x=x
sage: x
a + b

Here, I assigned a+b to x. But I can't 'unassign' it.

In Mathematica this can be done with Clear[x].

Thanks.

2015-03-27 04:11:57 +0200 marked best answer Why no help for print?

I wanted to find what the function print does, so I typed

print?

and pressed tab.

I get "No object 'print' currently defined.

Why is that?

2015-03-27 04:11:53 +0200 marked best answer How to get more uniform output from full_simplify

I do this,

sage: var('x1,t1,x2,t2,u,c',domain=RR);assume(u>0);assume(c>0);assume(c>u);
(x1, t1, x2, t2, u, c)
sage: T1 = (t1-((u*x1)/(c^2)))/sqrt(1-((u^2)/(c^2)))
sage: T2 = (t2-((u*x2)/(c^2)))/sqrt(1-((u^2)/(c^2)))
sage: dT = T2-T1
sage: view(dT.full_simplify())

And I get,

$\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{\sqrt{c - u} \sqrt{c + u} {\left(c^{2} t_{1} - c^{2} t_{2} - u x_{1} + u x_{2}\right)}}{c^{3} - c u^{2}}$

I put this expression in which is supposed to be the same,

sage: s = ((t2-t1)-((u/(c^2))*(x2-x1)))/sqrt(1-((u^2)/(c^2)))
sage: view(s.full_simplify())

And get this,

$\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{c^{2} t_{1} - c^{2} t_{2} - u x_{1} + u x_{2}}{\sqrt{c - u} \sqrt{c + u} c}$

It is not immediately apparent to me that dT and s are the same. But they are both equal as can be seen by,

sage: (s-dT).full_simplify()
0

This is something minor, but is there something I can do to get a simplified expression which is more uniform every time I use full_simplify()?

Thanks.

2015-03-27 04:10:24 +0200 marked best answer How to do latex typesetting in asksage

I've seen questions here with typeset expressions. But I can't find out how to do it. I searched for the strings "latex", "markdown", "mathjax", "typesetting" but can't find what I want.

Thanks in advance.

2015-03-27 04:08:17 +0200 marked best answer bool gives another unexpected result

Here is the output

sage: var('c,u,v',domain=RR);assume(v>0,u>0,c>u,c>v);
(c, u, v)
sage: assumptions()
[v > 0, u > 0, c > u, c > v]
sage: bool(c^2 - u*v >= 0)
False
sage: bool(c^2 - u^2 >= 0)
True
sage: bool(c^2 - v^2 >= 0)
True

I don't see how c^2 - v*u can not be larger than or equal to zero. Why does this happen? Is there a workaround?

2015-03-27 04:07:53 +0200 marked best answer Difference between var('x') and x=var('x')?

In some tutorials, when a variable is declared, it is done like,

var('x')

In some others, it is done like,

x = var('x')

What is the difference between the two, if any?

Also, is it better to ask this kind of basic question in the Asksage forum or the sage-support mailing list?

Thanks for your patience.