matrix^0, matrix.exp() and latex output of matrices
Alexander Heide
heide at ra.physik.uni-halle.de
Thu Mar 7 17:29:11 CET 2002
Here are some remarks and questions about matrices in GiNaC.
Have a look at this code:
#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
int main()
{
matrix A(2, 2, lst(0, 1, 1, 0));
A.print(print_latex(std::cout)); cout << endl;
cout << evalm(exp(A)) << endl;
cout << pow(A, 0).evalm() << endl;
cout << A.pow(0) << endl;
return 0;
}
The programm prints out:
[[0,1],[1,0]]
exp([[0,1],[1,0]])
1
and then runs forever (or until someone presses CTRL-C or turns off the
computer or whatever).
To have a nice matrix in LaTeX I would expect something like
\left(\begin{array}{ccc}0&1\\1&0\end{array}\right)
in the first line of the output. In the second line the expression keeps
unevaluated because of a lacking method
matrix matrix::exp(void) const;
The third line should be
[[1,0],[0,1]]
as well as the the fourth line.
And finally I have a (probably stupid) question: To construct an identity
2 x 2 matrix, I want to use
ex I = diag_matrix((lst(1, 1));
(More convenient would be a function like 'ex idenity_matrix(unsigned n)')
Now I want to add E to another matrix A, for instance
A = matrix(2, 2, lst(1, 0, 0, 1));
This works: evalm(A + E)
This works not: A.add(E), because E ist not a matrix object.
My question is: How con I convert E to a matrix object?
I've consulted the tutorial, but I couldn't find an answer to this
question.
More information about the GiNaC-list
mailing list