2018-03-16 19:06:43 -0500 received badge ● Popular Question (source) 2015-10-11 15:55:32 -0500 received badge ● Famous Question (source) 2014-06-28 20:14:50 -0500 marked best answer block_matrix confusion (matrix constructor rewrite in new versions of Sage) Solved - My mistake - I was running an older version of Sage I'm having trouble making use of the block_matrix function. I can't even recreate simple examples from the block_matrix documentation, for example sage: A = matrix(QQ, 2, 2, [3,9,6,10]) sage: X=block_matrix([ [A, -A], [~A, 100*A] ]) I receive the error "Must specify rows or cols for non-square block matrix." When I attempt to set those dimensions I continue to get errors. (My actual application of this is a bit more complicated, but the dimensions all work out. And I have used block_matrix in another program with symbolic entries. I must have gotten lucky.) I did not import numpy, I did not believe it was necessary. But there's no difference when I do. Thanks in advance to this magnificent community of sage-masters. Edit: I have an old version of Sage (4.4). I should have run block_matrix? to read my specific help file rather than the online documentation. It's working fine, I was simply using the wrong syntax for my version. 2014-06-28 20:14:50 -0500 marked best answer Large symbolic determinant I have a dense matrix with symbolic variable entries. I am interested in the equation that describes when the matrix is singular. So I have been having Sage compute the determinant of this matrix and set it equal to zero, and return this expression (a polynomial in several variables). However when the dimensions get larger (around 9 variables) Sage is taking an incredibly long amount of time to do it. (My program has to perform a number of other tasks as well, the determinant seems to be taking up all the run-time.) Is there any way I can speed up this kind of computation? 2014-06-28 20:14:49 -0500 marked best answer Finding roots of complex functions This could be a Maxima question as it relates to find_root, find_minimum_on_interval, etc. When I try to find the root of a function involving I (complex numbers) I get: TypeError: float() argument must be a string or a number For example, find_root(abs(1-exp(I*x)),-1,1). 2014-06-28 20:14:49 -0500 marked best answer Method for solving a large system of under-determined equations? I am trying to parametrize and find a family of solutions to some equations. (I am using the solve([eqns],vars) function.) Unfortunately, the equations are just complicated enough so that rather than parametrize, sage gives up and outputs the equations themselves. Here is a (partial) particular example that I had in mind. My real equation is actually a bit more complicated. But this is a point where it went from solving to simply spitting out the original equations. Here is the output: 10 equations, and 12 unknowns. {s0 + s2 + s4: 1} {s5: 0} {s0 + s1 + s2 + s3 + s4 + s5: 2} {w0: s5} {w1: -s4} {w2: s3} {(s0*w0 + s1*w1)*(s0*w0 + s1*w1 + s2*w2): s2*w0 + s3*w1} {w3: -s2} {w4: s1} {w5: -s0} Is there anything I can do? I've read the solve and x.solve pages, but I don't see a clear method I should try... =========== Edit: I'm looking for the simplest representation of this system of equations. I would like Sage to parametrize a few of the variables and solve for the others. For instance, a linear system example would be the following: eq1=a+b+c==2 eq2=b==1 solve([eq1,eq2],a,b,c) The output would be: a=1-r1, b=1, c=r1 Sage can do this using the solve function for small simple situations, even if they're non-linear equations. I want it to classify the family of all possible (real) solutions which satisfy all of the equations simultaneously. But it's stopping when I have a complicated system of equations. In essence I want it to "solve" the system of equations. Clearly this requires a few parameters, since there are more variables than equations... and since it's not a linear system I can't just ask a linear algebra student to do it. ;-) 2014-06-28 20:14:47 -0500 marked best answer Solve() confusion... I've been experimenting with the solve function, as it recently gave me unexpected results. In some instances sage outputs nonsensical solutions, but if I provide it with more information (even a trivial equation like x=x) it suddenly parametrizes and outputs correctly. Can someone explain what is going on in the following code and output? s=list(var('s_%d' % i) for i in range(3)); var('x y z'); print solve([],s_0,s_1,s_2) print solve([z==z],s_0,s_1,s_2) print solve([z==z,y==y],s_0,s_1,s_2) print solve([z==z,y==y,x==x],s_0,s_1,s_2) print solve([s_0==0],s_0,s_1,s_2); print solve([s_0==0,s_1==s_1],s_0,s_1,s_2); The result: [[s_0 == c1, s_1 == c2, s_2 == c3]] ({s_0: r1}, []) [[s_0 == r6, s_1 == r5, s_2 == r4]] [[s_0 == r9, s_1 == r8, s_2 == r7]] ([s_0 == 0], ) [[s_0 == 0, s_1 == r11, s_2 == r10]] 2014-06-28 20:14:47 -0500 marked best answer A list of symbolic variables Hello, I'm new to sage so I hope that I'm asking a very basic question. I'm trying to create a list of symbolic variables. I would like to be able to set the number of variables initially and then let sage create the list. I was (sort of) able to achieve this when I realized that the input for var is a string, so I wrote the following, which produces six symbolic variables for me: n=3; for i in range(2*n):       var('s_'+str(i)) In my context, the variables are actually real, and they satisfy a system of equations that I would also like sage to produce. By playing with strings, and then using eval on them so they became expressions, I was able to produce a few of the simpler equations, which sage can solve. But when I run for loops indexed by i I can never seem to actually refer to the variables indexed by i. For example, the following will not make sense to sage: for i in range(2*n):         s_i = i The only way I can think to achieve the above result is to create a string with a for loop that states the command I want, turn it into an expression, save it as an equation, and then include it in a big list of equations. Even so, I can't index the equations by i either, so I can't create the 2*n equations that I would need... I have to do a lot more with these variables, so I hope someone can tell me what I am doing terribly wrong. The first thing I want to do is create a second list, w, defined as: $w_k = s_{2n-k}$ 2014-01-24 23:10:03 -0500 received badge ● Popular Question (source) 2013-09-30 13:59:31 -0500 received badge ● Famous Question (source) 2013-08-02 13:34:36 -0500 received badge ● Notable Question (source) 2013-05-19 19:56:00 -0500 received badge ● Famous Question (source) 2013-04-06 20:33:32 -0500 received badge ● Great Question (source) 2013-01-01 11:44:19 -0500 received badge ● Famous Question (source) 2012-11-27 03:57:58 -0500 marked best answer A list of symbolic variables You're pretty close! The problem as you've noted is that "s_i" merely "s_i"; there's no rule that says that the parts of (would-be) variable names after underscores get interpolated in this way. Here's how I'd do it, assuming I've understood you correctly: sage: # first make a list of the variables sage: n = 3 sage: s = list(var('s_%d' % i) for i in range(2*n)) sage: w = list(var('w_%d' % i) for i in range(2*n)) sage: s [s_0, s_1, s_2, s_3, s_4, s_5] sage: w [w_0, w_1, w_2, w_3, w_4, w_5] sage: sage: # then make a list of equations sage: eqs = list(w[k] == s[2*n-k-1] for k in range(2*n)) sage: eqs [w_0 == s_5, w_1 == s_4, w_2 == s_3, w_3 == s_2, w_4 == s_1, w_5 == s_0] Note that I had to put a -1 in there to get the relations I think you were aiming at. If I've misunderstood it's easy to change. 2012-11-03 06:16:28 -0500 commented question Solve equations integrally If it were a polynomial in one variable you could use roots() and tell it to consider the integers ZZ. (e.g. http://ask.sagemath.org/question/66/how-to-get-all-numerical-solutions-of-an-equation ) 2012-11-03 06:10:02 -0500 commented question Solve equations integrally I don't believe Sage can do what you're asking, at least not out of the box without you coming up with your own algorithm. There are a few questions about this already, but I think this is the best explanation is here: http://ask.sagemath.org/question/790/finding-integer-solutions-to-systems-of-polynomial 2012-05-08 10:14:51 -0500 received badge ● Notable Question (source) 2012-04-05 09:47:25 -0500 received badge ● Popular Question (source) 2012-03-25 13:11:31 -0500 received badge ● Notable Question (source) 2012-03-16 09:15:50 -0500 received badge ● Notable Question (source) 2012-01-16 08:07:30 -0500 commented answer "New Worksheet" opens current worksheet and erases name Yes, it was a cache issue! I don't understand why. Thanks kcrisman! I cleared the cache in my browser and I can create new worksheets again. 2012-01-16 08:05:08 -0500 commented answer "New Worksheet" opens current worksheet and erases name Oh, I just meant that installing Sage via the package installer on Mandriva gives you Sage 4.4. I installed Sage 4.7 myself after I realized this wavelet module (pywavelets) wasn't working correctly. But I haven't cut ties with 4.4 completely. I use 4.7 if I remember to. :) 2012-01-14 05:35:01 -0500 answered a question "New Worksheet" opens current worksheet and erases name Sage 4.4 and Sage 4.7 under Firefox 9.0.1 is doing something similar to me right now. Whenever I hit 'new worksheet' it just pulls up the last worksheet I created. I tried updating Firefox but it hasn't helped. I'm using Mandriva Linux 2010, which for some reason wants to use Sage 4.4 by default. But both are giving me this issue... Am I only allowed to have 20 worksheets or something? 2011-11-26 11:48:19 -0500 received badge ● Popular Question (source) 2011-10-04 01:36:05 -0500 received badge ● Popular Question (source) 2011-09-24 16:19:34 -0500 marked best answer Method for solving a large system of under-determined equations? There is no closed form for the roots of a polynomial in general. So we'll have to assume that you can somehow compute roots. One nice trick to get a parametrization is to compute a Groebner basis in lexicographic order. You need to put your parameters last in the order of variables. Say, sage: R. = PolynomialRing(QQ, order='lex') sage: I = R.ideal([5*x - 1/3*y^2 - 2*y*z + y - 5/4*z^2, -3/2*x - 1/13*y*z + 4]) These are two (random) polynomial equations in three variables, so we expect the solution to be a curve. Indeed, it is: sage: I.dimension() 1 It is also an irreducible curve, that is, not two curves that are disjoint or intersect in a point: sage: I.primary_decomposition() [Ideal (52*y^2 + 352*y*z - 156*y + 195*z^2 - 2080, 39*x + 2*y*z - 104) of Multivariate Polynomial Ring in x, y, z over Rational Field] The Groebner basis in the given lexicographic order is: sage: I.groebner_basis() [x + 2/39*y*z - 8/3, y^2 + 88/13*y*z - 3*y + 15/4*z^2 - 40] The last variable (in the lexicographic order) is z, which we take to be the parameter. The second equation in the Groebner basis depends only on y and z, so if you plug in a value for z then it is a polynomial equation in a single variable. Solving this univariate polynomial equation yields multiple (in this case, two) solutions for y. Then plug y,z into the first equation of the Groebner basis. You get one polynomial equation in x, which you have to solve again. Hence, you have determined y(z) and x(y(z),z), that is, parametrized your curve by z. 2011-09-13 07:08:58 -0500 marked best answer Solve() confusion... Let's look one by one. print solve([],s_0,s_1,s_2) [[s_0 == c1, s_1 == c2, s_2 == c3]] Looks good - no equations, so any complex number (hence the c) will do for each variable. print solve([z==z],s_0,s_1,s_2) ({s_0: r1}, []) Hmm, this must be an artifact of the difference between single-variable and multivariable solve. Here Maxima gives us a r as well, so real number - not really what we want, in retrospect. print solve([z==z,y==y],s_0,s_1,s_2) [[s_0 == r6, s_1 == r5, s_2 == r4]] Seems fine except for the real versus complex issue. print solve([z==z,y==y,x==x],s_0,s_1,s_2) [[s_0 == r9, s_1 == r8, s_2 == r7]] Ditto. print solve([s_0==0],s_0,s_1,s_2); ([s_0 == 0], ) Huh, a tuple. I wonder if this is giving multiplicity of this solution? That is the default, I believe. See solve? for details. print solve([s_0==0,s_1==s_1],s_0,s_1,s_2); [[s_0 == 0, s_1 == r11, s_2 == r10]] This seems fine. Still, I agree that there isn't 100% uniformity here, so I'm opening Trac 10750 to track this issue. 2011-08-26 01:34:03 -0500 received badge ● Popular Question (source) 2011-07-20 06:04:07 -0500 asked a question WaveletPacket - wp['a'] vs wp.a I'm having trouble using pywt.WaveletPacket. The documentation and examples at http://www.pybytes.com/pywavelets/reg... are not helping me very much. This may be more of a lack of understanding python. For example after repeating these first few steps: import pywt x = [1, 2, 3, 4, 5, 6, 7, 8] wp = pywt.WaveletPacket(data=x, wavelet='db1', mode='sym') The documentation suggests accessing different levels by typing print wp['a'] but for me this results in gibberish. I am able to access the first level of decomposition by typing print wp.a However, I cannot access levels higher than this, only level 0 (print wp - which returns the original data in x) and level 1 (using wp.a or wp.d). In short, wp['a'] seems to be a completely different object from wp.a, and I cannot access higher level data, which I suspect is there, because print wp.maxlevel outputs 3, as it should in this case. ==== update ==== As I am writing this question out, I just now realized I can access the higher level data by typing print wp.a.a for example. Which is fairly intuitive. But what is the difference between wp['a'] and wp.a? Is the documentation simply incorrect? I apologize if this is more of a python question and not so much a sage question. 2011-04-02 15:52:31 -0500 marked best answer block_matrix confusion (matrix constructor rewrite in new versions of Sage) This works for me in 4.6.2: sage: A = matrix(QQ, 2, 2, [3,9,6,10]) sage: block_matrix([ [A, -A], [~A, 100*A] ]) [ 3 9| -3 -9] [ 6 10| -6 -10] [-----------+-----------] [-5/12 3/8| 300 900] [ 1/4 -1/8| 600 1000] Previously I think you had to write sage: A = matrix(QQ, 2, 2, [3,9,6,10]) sage: block_matrix([A, -A, ~A, 100*A]) [ 3 9| -3 -9] [ 6 10| -6 -10] [-----------+-----------] [-5/12 3/8| 300 900] [ 1/4 -1/8| 600 1000] or at least you did back in 4.5.1, and it looks like the constructor was rewritten not so long ago. Check your block_matrix's help.. or upgrade, I guess. :^)