[GiNaC-list] How to access matrix elements of an indexed expressions
Bastian Abt
spookyghost at mailbox.org
Sat Jan 11 10:40:43 CET 2025
Hi,
I want to use ginac to evaluate some complex expressions that evolve
some vector algebra. However, have some trouble working with the matrix
class. I have 2 questions:
1: Am I correct, that if i want to compute the Subtraction of two
vectors I should use the indexed variant?
2: How do I access elements of an expression?
I have included a small file that illustrates my problem?
Kind regards,
Spooky
#include <ginac/ginac.h> #include <iostream> int main(int argc,char **argv) {
using namespace GiNaC;
idx d(symbol("d"),3);
matrix m0 = matrix({{0,0,0}}), m1 = matrix({{1,0,0}});
indexed v0 = indexed(m0,d), v1 = indexed(m1,d);
// This seems wrong: std::cout<< (m1-m0).eval()<< std::endl;
// -> [[1,0,0]]-[[0,0,0]] // This seems right: std::cout<< (v1-v0).simplify_indexed()<< std::endl;
// -> [[1,0,0]].d // I can normally access matrix element using std::cout<< m1(0,0) << std::endl;
// -> 0 // But how can I access matrix elements of an expression? //
does not compile: // std::cout << "(v1-v0)(0,0): " << (v1-v0)(0,0) <<
std::end; return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ginac.de/pipermail/ginac-list/attachments/20250111/ecfca846/attachment.htm>
More information about the GiNaC-list
mailing list