Ask Your Question

David Ferrone's profile - activity

2023-08-06 11:26:44 +0200 received badge  Notable Question (source)
2022-07-04 09:09:10 +0200 received badge  Famous Question (source)
2019-11-26 20:57:26 +0200 received badge  Notable Question (source)
2018-03-17 01:06:43 +0200 received badge  Popular Question (source)
2015-10-11 22:55:32 +0200 received badge  Famous Question (source)
2014-06-29 03:14:50 +0200 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-29 03:14:50 +0200 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-29 03:14:49 +0200 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-29 03:14:49 +0200 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-29 03:14:47 +0200 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], [1])
[[s_0 == 0, s_1 == r11, s_2 == r10]]
2014-06-29 03:14:47 +0200 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-25 06:10:03 +0200 received badge  Popular Question (source)
2013-09-30 20:59:31 +0200 received badge  Famous Question (source)
2013-08-02 20:34:36 +0200 received badge  Notable Question (source)
2013-05-20 02:56:00 +0200 received badge  Famous Question (source)
2013-04-07 03:33:32 +0200 received badge  Great Question (source)
2013-01-01 18:44:19 +0200 received badge  Famous Question (source)
2012-11-27 10:57:58 +0200 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 12:16:28 +0200 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 12:10:02 +0200 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 17:14:51 +0200 received badge  Notable Question (source)
2012-04-05 16:47:25 +0200 received badge  Popular Question (source)
2012-03-25 20:11:31 +0200 received badge  Notable Question (source)
2012-03-16 15:15:50 +0200 received badge  Notable Question (source)
2012-01-16 15:07:30 +0200 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 15:05:08 +0200 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 12:35:01 +0200 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 18:48:19 +0200 received badge  Popular Question (source)
2011-10-04 08:36:05 +0200 received badge  Popular Question (source)
2011-09-24 23:19:34 +0200 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.<x,y,z> = 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.