Ask Your Question

k1's profile - activity

2022-10-28 15:45:59 +0200 received badge  Popular Question (source)
2022-06-23 12:19:02 +0200 received badge  Notable Question (source)
2021-04-30 02:45:50 +0200 received badge  Taxonomist
2017-10-19 11:46:46 +0200 received badge  Famous Question (source)
2017-09-28 00:24:33 +0200 received badge  Popular Question (source)
2017-09-18 01:45:50 +0200 received badge  Famous Question (source)
2017-09-18 01:45:50 +0200 received badge  Notable Question (source)
2016-05-13 03:40:05 +0200 received badge  Notable Question (source)
2015-11-17 12:00:37 +0200 received badge  Popular Question (source)
2015-02-10 13:28:41 +0200 received badge  Popular Question (source)
2014-06-29 14:29:12 +0200 received badge  Famous Question (source)
2014-06-29 14:29:12 +0200 received badge  Notable Question (source)
2014-06-29 06:17:49 +0200 received badge  Famous Question (source)
2014-06-29 06:17:49 +0200 received badge  Popular Question (source)
2014-06-29 06:17:49 +0200 received badge  Notable Question (source)
2014-06-29 03:15:36 +0200 marked best answer installation error

I tried to install sage from source and also from PPA on Ubuntu 12.10. Both of them finish the installation without any problem, but when I run sage I get the following error:

k1@Think1:~$ sagemath


| Sage Version 5.8, Release Date: 2013-03-15 | | Type "notebook()" for the browser-based notebook interface. | | Type "help()" for help. |


/usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/utils/path.py:289: > UserWarning: IPython dir '/home/k1/.sage/ipython-0.12' is not a writable location, using a temp directory.

" using a temp directory."%ipdir)

Traceback (most recent call last):

File "/usr/lib/sagemath/local/bin/sage-ipython", line 14, in <module> app.initialize()

File "<string>", line 2, in initialize

File "/usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error

return method(app, args, *kwargs)

File "/usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 313, in initialize

super(TerminalIPythonApp, self).initialize(argv)

File "<string>", line 2, in initialize

File "/usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error

return method(app, args, *kwargs)

File "/usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/application.py", line 333, in initialize

self.load_config_file()

File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/misc/interpreter.py", line 693, in load_config_file

get_ipython_dir(), 'sage').location

File "/usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/profiledir.py", line 209, in find_profile_dir_by_name

raise ProfileDirError('Profile directory not found in paths: %s' % dirname) ProfileDirError: Profile directory not found in paths: profile_sage

If you suspect this is an IPython bug, please report it at: https://github.com/ipython/ipython/is... or send an email to the mailing list at ipython-dev@scipy.org

You can print a more detailed traceback right now with "%tb", or use "%debug" to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via: c.Application.verbose_crash=True

But if I run it as root then it works fine. I have installed it all without root permission though. I thought it might be a permission problem and gave all the permissions for the files to the user k1, but still the problems exists.

So, I gained the permission to '/home/k1/.sage' and now it runs, but there are new errors:

[SageTerminalApp] Could not set security dir permissions to private.

[SageTerminalApp] Could not set pid dir permissions to private.

and I can't open the notebook().

the output of "ls -l /home/k1/ | grep .sage" is empty.

The output of "ls -l /home/k1/.sage" is :

total 28

drwsrwsrwt 2 k1 k1 4096 Mar 28 20:37 cache

drwsrwsrwt 2 k1 k1 4096 Mar 28 16:11 db

-rwxrwxrwt 1 k1 k1 0 Mar 29 17:39 gp-expect.log

-rwsrwsrwt 1 k1 k1 0 Mar 28 20:20 init.sage

drwsrwsrwt 3 root root 4096 Mar 29 17:39 ipython-0.12

drwsrwsrwt 2 k1 k1 4096 Mar 28 19:26 matplotlib-1.1.0

drwsrwsrwt 3 root ...

(more)
2014-06-29 03:12:48 +0200 marked best answer A combination of commands partial_fraction(x) and coefficient(x,n)

I have asked this question over here but I got no answer.

I am trying to do some iterative calculations where each time SAGE constructs a fraction and lists the coefficients in the partial fraction decomposition of that fraction. I realized that doing everything symbolically, SAGE wants to keep everything as integer as possible. So what it does is to simplify fractions like 1/(x-3/2) as 2/(2x-3) and then when I ask for

f.coefficient(x-3/2,-1)

it returns 0, while I expect it to return 1.

I have tried to solve things numerically, but there are two problems:

  1. The errors get really big after each iteration
  2. It takes much much longer to calculate it

Any suggestions to get SAGE to solve this is greatly appreciated.

2014-06-08 22:21:50 +0200 received badge  Popular Question (source)
2014-04-29 12:45:31 +0200 commented question derivative of MPolynomial_polydict

I included the complete code at the end of the post.

2014-04-29 02:27:25 +0200 asked a question derivative of MPolynomial_polydict

In a for loop I generate a list of functions, then I take their derivatives with respect to different variables. For example, in the follwoing, Y[0,0] is a 'MPolynomial_polydict', and is equal to

x_0_1*x_0_1 + x_0_0*x_1_1 + x_0_2*x_0_2 + x_1_2*x_1_2 + x_0_0*x_2_2 + x_1_1*x_2_2 - 1.00000000000000

and list_of_variables[0] = x_0_1. When I take the derivative of the mentioned polynomial with respect to the mentioned variable I should get 2*x_0_1, but instead I get:

sage: derivative(Y[0,0],list_of_variables[0])
x_0_1

When I try this manually, it gives me the correct answer though:

sage: derivative(x_0_1*x_0_1 + x_0_0*x_1_1 + x_0_2*x_0_2 + x_1_2*x_1_2 + x_0_0*x_2_2 + x_1_1*x_2_2 - 1.00000000000000,x_0_1)
2*x_0_1

So, for some reason it considers the two x_0_1's in the first term of my polynomial as independent variables when I construct them automatically. Any ideas on why this problem arises, and how to fix this?

Edit:

This is how I build my vaiables:

names = [ [[] for i in range(n)] for j in range(n) ]

for i in range(n):
    for j in range(i+1):
        names[i][j] = (SR('x_' + str(j) + '_' + str(i)))
        names[j][i] = (SR('x_' + str(j) + '_' + str(i)))

R = PolynomialRing(CC,names[i][j] for i in range(n) for j in range(n)])
R.gens()
R.inject_variables()

More edit: Here is a the complete code:

#########################################################################
# Build variables, and the matrix corresponding to it
#########################################################################

def build_variables(n):
    names = [ [[] for i in range(n)] for j in range(n) ]

    for i in range(n):
        for j in range(i+1):
            names[i][j] = (SR('x_' + str(j) + '_' + str(i)))
            names[j][i] = (SR('x_' + str(j) + '_' + str(i)))

    return(names)


#########################################################################
# Define the function f that maps a matrix to the coefficients of its characteristic polynomial
#########################################################################
def CharPoly(Mat):
    X = matrix(Mat)
    n = X.ncols()
    C_X = X.characteristic_polynomial()
    Y = []
    for i in range(n):
        Y.append(C_X[i])
    return(Y)


############################################################################
# This solves that lambda problem
############################################################################
def lambda_siep(G,L,iter=100,epsilon = .1):
                        # G is any graph on n vertices
                        # L is the list of n desired distinct eigenvalues
                        # m is the number of itterations of the Newton's method
                        # epsilon: the off-diagonal entries will be equal to epsilon

    n = G.order()
    my_variables = build_variables(n)

    R = PolynomialRing(CC,[my_variables[i][j] for i in range(n) for j in range(n)])
    R.gens()
    R.inject_variables()


    X = [ [ R.gens()[n*i+j] for i in range(n) ] for j in range(n) ]

    Y = matrix(CharPoly(X)) - matrix(CharPoly(diagonal_matrix(L)))

    J = matrix(R,n)
    for i in range(n):
        for j in range(n):
            J[i,j] = derivative(Y[0][i],my_variables[j][j])

    B = diagonal_matrix(L) + epsilon * G.adjacency_matrix()

    count = 0
    while count < iter:

        T = [ B[i,j] for i in range(n) for j in range(n)]

        C = (J(T)).solve_right(Y(T).transpose())
        LC = list(C)

        B = B - diagonal_matrix([LC[i][0] for i in range(n)])

        count = count + 1

    return(B)
2014-04-24 16:12:58 +0200 commented answer solving system of polynomial equations over reals using newton method

I worked out a Newton's method base technique and got some solutions that works for me, but the code is really ugly, so I am waiting to see if there are any better solutions out here.

2014-04-24 16:11:54 +0200 commented answer solving system of polynomial equations over reals using newton method

A Gorebner basis is not going to work for my problem, since my actual problem is much bigger, and even on 10 equations and 10 variables the Groebner basis gets really ugly. Thanks for the suggestions though.

2014-04-19 19:44:07 +0200 answered a question Running sage with files on DropBox

This is what I did:

sage -n '~/Dropbox/Sage'

It creates a folder called Sage.sagenb and it works like your local sagenb folder in Sage installation folder. Then it asks for admin password if it's the first time you're running it in that folder.

2014-04-19 19:30:30 +0200 marked best answer A combination of commands partial_fraction(x) and coefficient(x,n)

You can do something like this

sage: f = 1/(x-3/2)
sage: g = f.denominator()
sage: f.coeff(f.denominator(), -1) / g.leading_coeff(x)
1
2014-04-19 19:12:09 +0200 asked a question solving system of polynomial equations over reals using newton method

I have a set of polynomial equations and I want to find one of its real solutions close to some point, and I need only one solution. Here is an example:

This is the list of equations and variables:

Equations = [x_0*x_1*x_2*x_3 - x_0*x_1 - x_0*x_2 - x_0*x_3 - x_1*x_2 - x_1*x_3 + 2*x_0 + 2*x_1 - 448, -x_0*x_1*x_2 - x_0*x_1*x_3 - x_0*x_2*x_3 - x_1*x_2*x_3 + 3*x_0 +
3*x_1 + 2*x_2 + 2*x_3 + 452, x_0*x_1 + x_0*x_2 + x_0*x_3 + x_1*x_2 + x_1*x_3 + x_2*x_3 - 159, -x_0 - x_1 - x_2 - x_3 + 21]

Variables = [x_0, x_1, x_2, x_3]

If I ask Sage to solve this

S = solve(Equations,Variables)

it returns a bunch of solutions. But in some cases it doesn't give me any real solutions. I can prove that the above set of equations has a real solution close to [2,4,7,8]. Is there any way that I can perform an algorithm like the Newton's method with the start point [2,4,7,8], and find that real solution?

2014-04-12 17:32:00 +0200 marked best answer installation error

Hi,

As you can see with the output of ls, some of the directory within .sage are owned by root, namely ipython-0.12, sage_notebook.sagenb and tmp. I don't know how such a thing could happen ! You can change the permissions with the command

sudo chown k1:k1 -R .sage

The command chown is for modifying users, k1:k1 means that you change the user and the group to k1 and -R is for recursive.

After that, it may work.

Vincent

2013-06-15 15:55:12 +0200 received badge  Nice Answer (source)
2013-06-14 09:57:10 +0200 received badge  Teacher (source)
2013-06-14 09:57:10 +0200 received badge  Self-Learner (source)
2013-06-13 19:10:14 +0200 commented question notebook default directory

How do one go to close a thread?

2013-06-13 19:10:14 +0200 received badge  Commentator
2013-06-13 19:09:31 +0200 answered a question notebook default directory

Just wrote

sage -n 'directory'

and it worked.

2013-06-13 19:08:30 +0200 commented question notebook default directory

easy enough. Thanks for the help. I just used `sage -n '/home/k1/Dropbox/Math/Scripts/Sage'` and it worked.

2013-06-13 15:43:44 +0200 asked a question notebook default directory

I want to change the default directory of notebook. I've learned that I can run

notebook("directory")

to have sage save and open worksheets from that directory, but I generally run

sage -notebook

from terminal. Is there a way to change the default directory for sage? or run it in a directory directly from terminal?

PS: My main reason for doing this is to connect the sage to my Dropbox in order to have a backup of all my worksheets. I've recently lost a whole bunch of them due some problems.

2013-05-01 17:19:44 +0200 commented answer Ignoring the very small imaginary part

Thank you very much. It worked great.

2013-05-01 17:19:20 +0200 marked best answer Ignoring the very small imaginary part

Hi,

I would prefer to have a method .real() for a complex matrix as there exists one for complex number::

sage: CC(1,0.5).real()
1.00000000000000

But it does not exist yet! Moreover, using .real() ignore all imaginary part. Here is a function that makes the job:

trunc_small_imag = lambda x: x.real() if abs(x.imag()) < .000001 else x
mat_trunc_small_imag = lambda m: m.parent()(map(trunc_small_imag, m.list()))

And here is an example:

sage: m = matrix([[CC(1,.0000001), CC(2,-0.5)],[CC(2,0.4),CC(1.1,-.000000004)]])
sage: mat_trunc_small_imag(m)
[                      1.00000000000000 2.00000000000000 - 0.500000000000000*I]
[2.00000000000000 + 0.400000000000000*I                       1.10000000000000]
2013-05-01 16:03:09 +0200 asked a question Ignoring the very small imaginary part

I am generating a matrix that its entries come from roots of a polynomial which are all real. Due to calculation errors sage returns entries such as: -2.8 + 2.2e-16*I

How can I ask sage to ignore the small imaginary part and return -2.8?

2013-04-17 19:47:31 +0200 commented question calling maple

BTW, is there an easy to understand instruction on how to apply patches? I found [this](http://www.sagemath.org/doc/developer/patching_spkgs.html) but it doesn't seem like what I need.

2013-04-17 19:38:31 +0200 commented question calling maple

Here is the output: "bash: /home/k1/sage5.8/spkg/bin:/home/k1/sage5.8/local/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/k1/.rvm/bin: No such file or directory" But it doesn't mean much to me!