Ask Your Question

Revision history [back]

Just after defining dAbar, type:

sage: dAbar = dAbar.dense_matrix()

And it will work.

Just after After defining dAbar, just type:

sage: dAbar = dAbar.dense_matrix()

And it will work.

Now, here are some explanations that may help you to understand what happened, tha may help in further cases (look to the Traceback). You defined your matrix in a sparse way: you only defined the diagonal assuming that the other values are zero. Hence, instead of storing all entries of the matrix, Sage only stores the interesting entries in a dictionary, hence the name sparse matrix.

But, at some point (during the .transpose() operation), probably to maintain the sparse structure, Sage checks whether some entries are zero. For this, it needs to be sure, hence it uses the safe complex interval arithmetic (where a complex number is approximated by a pair of floating point real intervals containing it).

Unfortunately, as explained in my previous answer, elements of the Complex Interval Field (named CIF) do not have a .sech() method, and you got an error. If you transform your matrix into a dense one (where zeros are explicitely written everywhere), this test is not done and the error does not appear.

By the way, there is another workaround in your case. Before doing any computation, redefine the sech() function (as explained in my previous answer), so that it will work for Complex Interval Field elements. Before any computation, just type:

sage: sech = lambda x: 2*exp(-x)/(1+exp(-2*x))

And, since the .exp() method is defined for elements of CIF, then you will not encounter the problem.

click to hide/show revision 3
link to previous answer

After defining dAbar, just type:

sage: dAbar = dAbar.dense_matrix()

And it will work.

Now, here are some explanations that may help you to understand what happened, tha may help in further cases (look to the Traceback). You defined your matrix in a sparse way: you only defined the diagonal assuming that the other values are zero. Hence, instead of storing all entries of the matrix, Sage only stores the interesting entries in a dictionary, hence the name sparse matrix.

But, at some point (during the .transpose() operation), probably to maintain the sparse structure, Sage checks whether some entries are zero. For this, it needs to be sure, hence it uses the safe complex interval arithmetic (where a complex number is approximated by a pair of floating point real intervals containing it).

Unfortunately, as explained in my previous answer, answer, elements of the Complex Interval Field (named CIF) do not have a .sech() method, and you got an error. If you transform your matrix into a dense one (where zeros are explicitely written everywhere), this test is not done and the error does not appear.

By the way, there is another workaround in your case. Before doing any computation, redefine the sech() function (as explained in my previous answer), so that it will work for Complex Interval Field elements. Before any computation, just type:

sage: sech = lambda x: 2*exp(-x)/(1+exp(-2*x))

And, since the .exp() method is defined for elements of CIF, then you will not encounter the problem.

After Just after defining dAbar, just type:

sage: dAbar = dAbar.dense_matrix()

And it will work.

Now, here are some explanations that may help you to understand what happened, tha may help in further cases (look to the Traceback). You defined your matrix in a sparse way: you only defined the diagonal assuming that the other values are zero. Hence, instead of storing all entries of the matrix, Sage only stores the interesting entries in a dictionary, hence the name sparse matrix.

But, at some point (during the .transpose() operation), probably to maintain the sparse structure, Sage checks whether some entries are zero. For this, it needs to be sure, hence it uses the safe complex interval arithmetic (where a complex number is approximated by a pair of floating point real intervals containing it).

Unfortunately, as explained in my previous answer, elements of the Complex Interval Field (named CIF) do not have a .sech() method, and you got an error. If you transform your matrix into a dense one (where zeros are explicitely written everywhere), this test is not done and the error does not appear.

By the way, there is another workaround in your case. Before doing any computation, redefine the sech() function (as explained in my previous answer), so that it will work for Complex Interval Field elements. Before any computation, just type:

sage: sech = lambda x: 2*exp(-x)/(1+exp(-2*x))

And, since the .exp() method is defined for elements of CIF, then you will not encounter the problem.