]> www.ginac.de Git - ginac.git/blobdiff - doc/tutorial/ginac.texi
simplify_indexed() recognizes linear combinations of matrices with numeric
[ginac.git] / doc / tutorial / ginac.texi
index fe09793d0f8b91e24b5f867d004be03c8870dc98..3bebde561dc772e51a056ad1d083dc1f519466f9 100644 (file)
@@ -1724,17 +1724,15 @@ tensor).
 @subsection Linear algebra
 
 The @code{matrix} class can be used with indices to do some simple linear
-algebra (products of vectors and matrices, traces and scalar products):
+algebra (linear combinations and products of vectors and matrices, traces
+and scalar products):
 
 @example
 @{
     idx i(symbol("i"), 2), j(symbol("j"), 2);
     symbol x("x"), y("y");
 
-    matrix A(2, 2), X(2, 1);
-    A.set(0, 0, 1); A.set(0, 1, 2);
-    A.set(1, 0, 3); A.set(1, 1, 4);
-    X.set(0, 0, x); X.set(1, 0, y);
+    matrix A(2, 2, lst(1, 2, 3, 4)), X(2, 1, lst(x, y));
 
     cout << indexed(A, i, i) << endl;
      // -> 5
@@ -1743,20 +1741,20 @@ algebra (products of vectors and matrices, traces and scalar products):
     cout << e.simplify_indexed() << endl;
      // -> [[ [[2*y+x]], [[4*y+3*x]] ]].i
 
-    e = indexed(A, i, j) * indexed(X, i);
+    e = indexed(A, i, j) * indexed(X, i) + indexed(X, j) * 2;
     cout << e.simplify_indexed() << endl;
-     // -> [[ [[3*y+x,4*y+2*x]] ]].j
+     // -> [[ [[3*y+3*x,6*y+2*x]] ]].j
 @}
 @end example
 
-You can of course obtain the same results with the @code{matrix::mul()}
-and @code{matrix::trace()} methods but with indices you don't have to
-worry about transposing matrices.
+You can of course obtain the same results with the @code{matrix::add()},
+@code{matrix::mul()} and @code{matrix::trace()} methods but with indices you
+don't have to worry about transposing matrices.
 
 Matrix indices always start at 0 and their dimension must match the number
 of rows/columns of the matrix. Matrices with one row or one column are
 vectors and can have one or two indices (it doesn't matter whether it's a
-row or a columnt vector). Other matrices must have two indices.
+row or a column vector). Other matrices must have two indices.
 
 You should be careful when using indices with variance on matrices. GiNaC
 doesn't look at the variance and doesn't know that @samp{F~mu~nu} and