Ask Your Question

Thrash's profile - activity

2019-10-12 14:56:47 -0500 received badge  Popular Question (source)
2019-09-21 07:21:53 -0500 received badge  Famous Question (source)
2019-04-02 15:56:58 -0500 received badge  Notable Question (source)
2019-02-28 11:01:04 -0500 commented question Evaluate polynomial expression on matrices

Thanks for the clarification!

2019-02-28 04:53:38 -0500 received badge  Nice Question (source)
2019-02-27 17:04:28 -0500 asked a question Evaluate polynomial expression on matrices

How can I construct a map $M_2(\mathbb Q)^3 \to M_2(\mathbb Q), (A,B,C) \mapsto (AB-BA)C$ where $M_2(\mathbb Q)$ denotes the space of 2x2 matrices.

sage: x,y,z = var('x y z')
sage: f=(x*y-y*x)*z
sage: f
0
2019-01-23 08:22:54 -0500 received badge  Good Question (source)
2019-01-22 13:51:07 -0500 commented answer Bug in computing sum (of binomials)

Thanks for the fast answer and the fast ticket report!

2019-01-22 12:40:26 -0500 received badge  Nice Question (source)
2019-01-22 11:38:13 -0500 asked a question Bug in computing sum (of binomials)

One gets a wrong output when running the following command:

sage: sum(binomial(1,n),n,0,oo)
3

The output should be $2$ instead of $3$. Compare:

sage: sum(binomial(1,n),n,0,oo,algorithm="sympy")
2
2019-01-17 15:22:57 -0500 received badge  Good Answer (source)
2019-01-17 11:38:33 -0500 received badge  Nice Answer (source)
2019-01-17 06:57:24 -0500 received badge  Teacher (source)
2019-01-16 22:27:41 -0500 asked a question How can I solve the following (linear) differential equation?

I want Sage to solve this equation: $y'''-3y''+y'-5y=0$.

Both

y=function('y')(x) 
desolve(diff(y,3)-3*diff(y,2)+diff(y,1)-5*y,y)

and

giac("desolve([y'''-3y''+y'-5y],y)").sage()

result in errors.

2019-01-16 20:03:52 -0500 answered a question How to solve this system of equation in sage?

Considering the notation of your first (general) example, simply copy the following code (as a script) and adjust $k$ as desired.

k = 3
r = var('r')
c = list(var('c%d' % i) for i in [1..k])
l = list(var('l%d' % i) for i in [1..k])
x = list(var('x%d' % i) for i in [1..k])
eqn_list = list(sum(x[i]*l[j]^i for i in range(k))==c[j]+r^(j+1) for j in range(k))
sol = solve(eqn_list,x)

Output of sol:

sage: sol
[[x1 == ((l1^2*l2 - l1*l2^2)*r^3 + (c3*l2 - c2*l3)*l1^2 - (l1^2*l3 - l1*l3^2)*r^2 + (l2^2*l3 - l2*l3^2)*c1 - (c3*l2^2 - c2*l3^2)*l1 + (l2^2*l3 - l2*l3^2)*r)/(l1^2*(l2 - l3) + l2^2*l3 - l2*l3^2 - (l2^2 - l3^2)*l1), x2 == -((l1^2 - l2^2)*r^3 - (c2 - c3)*l1^2 - c3*l2^2 + c2*l3^2 - (l1^2 - l3^2)*r^2 + (l2^2 - l3^2)*c1 + (l2^2 - l3^2)*r)/(l1^2*(l2 - l3) + l2^2*l3 - l2*l3^2 - (l2^2 - l3^2)*l1), x3 == ((l1 - l2)*r^3 - (l1 - l3)*r^2 - (c2 - c3)*l1 + c1*(l2 - l3) - c3*l2 + c2*l3 + (l2 - l3)*r)/(l1^2*(l2 - l3) + l2^2*l3 - l2*l3^2 - (l2^2 - l3^2)*l1)]]

An alternative way would be to go via a matrix (which is notably faster).

k = 3
r = var('r')
c = list(var('c%d' % i) for i in [1..k])
l = list(var('l%d' % i) for i in [1..k])
A = matrix(list(l[j]^i for i in range(k)) for j in range(k))
v = vector(c[j]+r^(j+1) for j in range(k))
sol = A\v

Output of sol:

sage: sol
((r^3 - c1 + c3 - (r^2 - c1 + c2 - r)*(l1 - l3)/(l1 - l2) - r)*(l1^2 - (l1^2 - l2^2)*l1/(l1 - l2))/(l1^2 - l3^2 - (l1^2 - l2^2)*(l1 - l3)/(l1 - l2)) + c1 + (r^2 - c1 + c2 - r)*l1/(l1 - l2) + r, (r^3 - c1 + c3 - (r^2 - c1 + c2 - r)*(l1 - l3)/(l1 - l2) - r)*(l1^2 - l2^2)/((l1^2 - l3^2 - (l1^2 - l2^2)*(l1 - l3)/(l1 - l2))*(l1 - l2)) - (r^2 - c1 + c2 - r)/(l1 - l2), -(r^3 - c1 + c3 - (r^2 - c1 + c2 - r)*(l1 - l3)/(l1 - l2) - r)/(l1^2 - l3^2 - (l1^2 - l2^2)*(l1 - l3)/(l1 - l2)))

This is indeed the same solution.

2019-01-16 18:31:24 -0500 marked best answer Save output as a text file (not in a mathematical sense)

How can I save an output directly as a text file (without copy paste)?

2019-01-16 18:24:01 -0500 marked best answer Define map with vector argument(s)

(Is it possible to use LaTeX code here in order to get a nice output?)

Let's say I want to put the map phi: Q^3 x Q^3 -> Q defined by (x,y) -> x1y1 - x2y2 + x3*y3 into Sage. How do I do this? I want to have later for example:

sage: x=vector((1,2,3)); y=vector((2,3,1))
sage: phi(x,y)

Then the output should be the value phi(x,y).

Is it only possible via the def command (withx[1] etc.)? Or how can you specify the domain of a map? How would you do this?

2019-01-16 18:22:11 -0500 received badge  Popular Question (source)
2019-01-16 18:09:09 -0500 marked best answer Rename xbar and factorize/simplify

See below (my answer)

When generating fraction fields, is it possible to rename xbar to x and do a factorization? Consider the following example:

sage: R=PolynomialRing(QQ, ['x','y','a4','a6'])
sage: R.inject_variables()
Defining x, y, a4, a6
sage: I=R.ideal(x^3+a4*x+a6-y^2)
sage: Q=R.quotient(I)
sage: F=Q.fraction_field()
sage: E=EllipticCurve(F,[a4,a6])
sage: E.discriminant()
-64*a4bar^3 - 432*a6bar^2
sage: _.factor()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-149-995262737325> in <module>()
----> 1 _.factor()

/usr/lib/python2.7/site-packages/sage/categories/quotient_fields.pyc in factor(self, *args, **kwds)
    352                 (x + y)^-1 * y * x
    353             """
--> 354             return (self.numerator().factor(*args, **kwds) /
    355                     self.denominator().factor(*args, **kwds))
    356 

/usr/share/sage/source/sage/structure/element.pyx in sage.structure.element.Element.__getattr__ (/build/sagemath/src/sage-8.0/src/src/build/cythonized/sage/structure/element.c:4290)()
    457             AttributeError: 'LeftZeroSemigroup_with_category.element_class' object has no attribute 'blah_blah'
    458         """
--> 459         return self.getattr_from_category(name)
    460 
    461     cdef getattr_from_category(self, name):

/usr/share/sage/source/sage/structure/element.pyx in sage.structure.element.Element.getattr_from_category (/build/sagemath/src/sage-8.0/src/src/build/cythonized/sage/structure/element.c:4399)()
    470         else:
    471             cls = P._abstract_element_class
--> 472         return getattr_from_other_class(self, cls, name)
    473 
    474     def __dir__(self):

/usr/share/sage/source/sage/structure/misc.pyx in sage.structure.misc.getattr_from_other_class (/build/sagemath/src/sage-8.0/src/src/build/cythonized/sage/structure/misc.c:1927)()
    292         dummy_error_message.cls = type(self)
    293         dummy_error_message.name = name
--> 294         raise dummy_attribute_error
    295     cdef PyObject* attr = _PyType_Lookup(<type>cls, name)
    296     if attr is NULL:

AttributeError: 'QuotientRing_generic_with_category.element_class' object has no attribute 'factor'

I want to have -16*(4*a4^3 + 27*a6^2) as the output. Is this possible? Another try:

sage: factor(_)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-173-af2394367aae> in <module>()
----> 1 factor(_)

/usr/lib/python2.7/site-packages/sage/arith/misc.pyc in factor(n, proof, int_, algorithm, verbose, **kwds)
   2279             return n.factor(proof=proof, **kwds)
   2280         except AttributeError:
-> 2281             raise TypeError("unable to factor n")
   2282         except TypeError:
   2283             # Just in case factor method doesn't have a proof option.

TypeError: unable to factor n
sage: factor(_, proof=false)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-174-78e3719752df> in <module>()
----> 1 factor(_, proof=false)

/usr/lib/python2.7/site-packages/sage/arith/misc.pyc in factor(n, proof, int_, algorithm, verbose, **kwds)
   2279             return n.factor(proof=proof, **kwds)
   2280         except AttributeError:
-> 2281             raise TypeError("unable to factor n")
   2282         except TypeError:
   2283             # Just in case factor method doesn't have a proof option.

TypeError: unable to factor n
2019-01-16 04:07:19 -0500 received badge  Nice Question (source)
2019-01-15 14:54:02 -0500 commented question Wrong solution/output for differential equation

How do you "access" those answers? For example, desolve(diff(y)==4*y/x+x*sqrt(y),y,ics=[1,1],algorithm="giac") gives ValueError: unknown algorithm giac.

2019-01-14 10:54:14 -0500 asked a question Wrong solution/output for differential equation

As the user rburing advised in the thread https://ask.sagemath.org/question/449... I'm opening this one now.

When running the following code, one obtains a wrong output:

y=function('y')(x)
desolve(diff(y)==4*y/x+x*sqrt(y),y,ics=[1,1]).factor()

The output is 1/4*x^4*(log(x) - 2)^2 instead of 1/4*x^4*(log(x) + 2)^2. Mathematica however outputs both (by running DSolve[{D[y[x], x] == 4*y[x]/x + x*Sqrt[y[x]], y[1] == 1}, y[x], x]).

2019-01-13 21:44:08 -0500 marked best answer Combine plots with built-in Maxima, trajectory in Sage available?

I want to combine the following plots as one output figure:

maxima('plotdf(4*y/x+x*sqrt(y),[trajectory_at,1,1],[x,0,4],[y,0,10])')
maxima('plot2d(1/4*x^4*(log(x)+2)^2,[x,0,4],[y,0,10])')

How can I achieve that? However, if there is any way to output a trajectory by Sage directly, I would be very happy. With pure Sage, I've just achieved this so far:

plot_slope_field(4*y/x+x*sqrt(y),(x,0,4),(y,0,10),headaxislength=3,headlength=3)
2019-01-13 21:39:24 -0500 commented answer Combine plots with built-in Maxima, trajectory in Sage available?

I consider this behavior a bug. Can you please open a ticket?

2019-01-13 05:25:52 -0500 received badge  Good Question (source)