Ask Your Question

Erfan's profile - activity

2018-06-28 10:20:49 -0500 received badge  Notable Question (source)
2015-09-10 15:26:28 -0500 received badge  Popular Question (source)
2014-06-11 20:46:32 -0500 received badge  Notable Question (source)
2014-05-29 20:05:31 -0500 received badge  Popular Question (source)
2013-05-15 18:02:42 -0500 asked a question static typing of mpf variables in cython

Hello,

I am a new user of cython. I was looking for the static typing of python's mpf type variables in cython for speed up.

For example:

python: N=10 static typing in cython: cdef int N=10

Now I'm looking for the equivalent for mpf variables:

python: from mpmath import mpf , N = mpf(10)

cython: ??? maybe sth like: 'cdef mpf_t N=10' but this doesn't work.

Thank you,

2013-01-15 11:29:40 -0500 answered a question Matrices and mpmath

Thanks a lot!

2013-01-15 11:16:05 -0500 answered a question Matrices and mpmath

I'm trying to due high precision numerical work so I need to use mpf numbers. When we define matrices in sage using mpmath it seems that it loses the linalg operations such as inversion, so you can't calculate the inverse of a matrix as before. Is there a specific command for it?

For example:

Sage: M=matrix([[2,0],[0,2]])

Sage: M**-1

[1/2 0]

[ 0 1/2]

But:

Sage: M=mp.matrix([[2,0],[0,2]])

Sage: M**-1

Gives the error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_27.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("TT1tcC5tYXRyaXgoW1syLDBdLFswLDJdXSkKTSoqLTE="),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module>

File "/tmp/tmps6geGH/___code___.py", line 4, in <module> exec compile(u'M**-_sage_const_1 File "", line 1, in <module>

File "/sagenb/sage_install/sage-5.4-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/mpmath/matrices/matrices.py", line 603, in __pow__ raise ValueError('only integer exponents are supported') ValueError: only integer exponents are supported

It seems that Sage is not very friendly with mpmath. Is there something that should be imported or a specific command to use?

Thank you.

2013-01-15 10:13:17 -0500 answered a question Matrices and mpmath

Thank you. That works. I have to then alter my code in ipython a bit..

2013-01-15 10:11:08 -0500 received badge  Supporter (source)
2013-01-15 09:08:51 -0500 asked a question Matrices and mpmath

Hello, I'm trying to work with matrices. I type matrix(4) and it gives me a 4 by 4 matrix of zeros which is fine. But when I use the command from mpmath import * then try to create matrices with the same command (matrix(4)) it gives an error message as below:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_10.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dD1tYXRyaXgoNSk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>

  File "/tmp/tmpdJ1MFV/___code___.py", line 3, in <module>
    exec compile(u't=matrix(_sage_const_5 )
  File "", line 1, in <module>

  File "/sagenb/sage_install/sage-5.4-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/mpmath/matrices/matrices.py", line 332, in __init__
    raise TypeError('could not interpret given arguments')
TypeError: could not interpret given arguments

Since I need this command (from mpmath import *) for other operations, I have to use it. On the other hand it disrupts my matrix calculations. Is there anyway which I can have both working together in Sage similar to ipython?

Any help would be appreciated. Thank you.