Hello, On Mon, Feb 19, 2007 at 08:56:30PM -0300, Charlls Quarra wrote:
I just noted that the following write access attempt will fail:
matrix foo(1 , 2); for (int i=0 ; i< 2 ; i++) { foo(0,i) = matrix(2,2); } ex_to<matrix>( foo(0,1) )(1,1) = 34; cout << "it was wrote -> " << ex_to<matrix>( foo( 0 , 1 ) )(1,1) << endl;
[error message snipped] ex_to<T> returns reference to _constant_ object (otherwise reference count would be broken), so you can't assign anything to such object.
any idea how to write to the entries of a submatrix in this way?
There is no way to do this (leaving aside evil hacks). Back to the original task:
i would also want to make computations with an object like D( f_{i} ) / dx_{j} dx_{k}
You don't have to use some GiNaC class to represent such objects, e.g. #include <iostream> #include <vector> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main(int argc, char** argv) { symbol x("x"), y("y"), u("u"), v("v"), w("w"), a("a"), b("b"), c("c"); std::vector<symbol> X(2); X[0] = x; X[1] = y; std::vector<ex> F(2); F[0] = a*x + b*y + c*x*y; F[1] = u*pow(x,2) + v*pow(y,2) + w*x; std::vector<matrix> D2F(2); for (size_t i=0; i < 2; i++) { D2F[i] = matrix(2, 2); for (size_t j=0; j < 2; j++) for (size_t k=0; k <= j; k++) { D2F[i](j, k) = F[i].diff(X[j]).diff(X[k]); D2F[i](k, j) = D2F[i](k, j); // suppose functions are smooth enough } } for (size_t i=0; i<2; i++) cout << "D^2(" << F[i] << ") = " << D2F[i] << endl; return 0; } Best regards, Alexei -- All science is either physics or stamp collecting.