Ask Your Question

Greg Marks's profile - activity

2019-10-08 03:09:09 +0200 received badge  Notable Question (source)
2016-12-02 13:58:00 +0200 received badge  Popular Question (source)
2014-12-27 04:59:44 +0200 received badge  Famous Question (source)
2013-07-09 23:46:27 +0200 received badge  Notable Question (source)
2013-02-08 21:53:18 +0200 asked a question backslash operator on RDF matrices

I've discovered that the backslash operator produces a weird type error when used on matrices with Real Double Field entries:

----------------------------------------------------------------------
| Sage Version 5.6, Release Date: 2013-01-21                         |
| Type "notebook()" for the browser-based notebook interface.        |
| Type "help()" for help.                                            |
----------------------------------------------------------------------
sage: A = matrix(QQ, 3, [1,2,4,2,3,1,0,1,2])
sage: B = matrix(QQ, 3, 2, [1,7,5,2,1,3])
sage: A\B
[  -1    1]
[13/5 -3/5]
[-4/5  9/5]
sage: A = matrix(RDF, 3, [1,2,4,2,3,1,0,1,2])
sage: B = matrix(RDF, 3, 2, [1,7,5,2,1,3])
sage: A\B
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/gtmarks/<ipython console> in <module>()

/usr/local/sage-5.6/local/lib/python2.7/site-packages/sage/misc/preparser.pyc in __mul__(self, right)
   1398             (0.0, 0.5, 1.0, 1.5, 2.0)
   1399         """
-> 1400         return self.left._backslash_(right)
   1401 
   1402 

/usr/local/sage-5.6/local/lib/python2.7/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix._backslash_ (sage/matrix/matrix2.c:3658)()

/usr/local/sage-5.6/local/lib/python2.7/site-packages/sage/matrix/matrix_double_dense.so in sage.matrix.matrix_double_dense.Matrix_double_dense.solve_right (sage/matrix/matrix_double_dense.c:11636)()

TypeError: vector of constants over Real Double Field incompatible with matrix over Real Double Field

I don't understand the final "imcompatibility" message: both the vector and the matrix are RDF type, so how could they be incompatible? This is a small version of a problem I encountered in the context of an attempt to demonstrate to a linear algebra class the computation time of solving systems of linear equations via LU factorization versus via matrix inversion by naive methods; to make the case for LU, I have to avoid various optimized algorithms built into SAGE. (Perhaps I should be using a call to LAPACK or something for this demonstration?)

2013-01-17 14:06:48 +0200 received badge  Popular Question (source)
2012-03-25 19:52:16 +0200 commented answer Add plots with different ymin, ymax parameters?

Thank you for your helpful answer, which solves my problem. The fact that ymin and ymax can be used as arguments in plot() gives them the illusion of being local variables, although, as you explain, and as my example illustrates, this is not the case. Of course, the fact that ymin and ymax don't appear in the documentation of "plot" as plot options is an indication of the true situation.

2012-03-25 19:42:00 +0200 received badge  Supporter (source)
2012-03-21 10:02:50 +0200 received badge  Nice Question (source)
2012-03-17 21:45:01 +0200 received badge  Student (source)
2012-03-17 19:50:35 +0200 received badge  Editor (source)
2012-03-17 19:38:30 +0200 asked a question Add plots with different ymin, ymax parameters?

I would like to combine graphs of single-variable functions with different vertical ranges specified for each.  As a test, I tried:

p=plot(x^3, x, -2, 2, ymin=-1, ymax=1)
q=plot(exp(x), x, -2, 2, ymin=0, ymax=4)
(p+q).show()

hoping to display the two graphs with the appropriate vertical ranges, but this does not give the desired result: the second ymin/ymax specification apparently overrides the first.  Various similar attempts also failed.  Is there a syntax that makes this work? 

(Obviously, in this test case, one could simply change the horizontal range in each plot to produce the desired vertical range, but this would be tedious if one were adding a larger number of plots involving more complicated functions.)