(kill (all), load (eigen), 0);
0;

(x : matrix ([1, 2, 3], [9, 18, 30], [12, 48, 60]),
 y : gramschmidt (x),
 expand (y, 0, 0));
''([[1,2,3],[-3^2/(2*7),-3^2/7,3*5/(2*7)],[-2^4*3/5,2^3*3/5,0]]);

map (innerproduct, [y[1], y[2], y[3]], [y[2], y[3], y[1]]);
[0, 0, 0];

(kill (x),
 ip (f, g) := integrate (f * g, 'x, a, b),
 ev (y : gramschmidt ([1, sin(x), cos(x)], ip), a= -%pi/2, b=%pi/2));
[1, sin(x), (%pi*cos(x) - 2)/%pi];

map (ip, [y[1], y[2], y[3]], [y[2], y[3], y[1]]), a= -%pi/2, b=%pi/2;
[0, 0, 0];

(load("nchrpl"),0);
0$

mattrace(matrix());
0$

mattrace(matrix([]));
0$

mattrace(matrix([a,b],[c,d]));
a + d$

mattrace(matrix([a,b],[c,d],[p,q]));
a + d$

/* Regression test for SF bug 2721670 */
(a[1,1] : 42, mattrace(matrix([1,2],[5,6])));
7$

(remarray(a),0);
0$

/* from mailing list 2009-08-17 "bugs on wxMaxima 5.19.1" */

block ([D1, uv], local (dmatrix),
 /* diag_matrix and diag involve loading big blobs of stuff, and diagmatrix isn't suitable ... sigh. */
 dmatrix (L) := block ([M, n : length (L)], M : zeromatrix (n, n), for i thru n do M[i, i] : L[i], M),
 D1 : matrix ([3, 2, 1, -5], [-1, 2, 1, -3], [5, -1, 2, 4], [3, 1, -1, 5]),
 uv : block([ratmx : true], similaritytransform (D1)),
 /* ratsimp or radcan could help here, but ratsimp simplifies leftmatrix . D1 . rightmatrix
  * incorrectly ... sigh. Also mat_norm could help but it's embedded in a big blob ... sigh.
  */
 float (dmatrix (uv[1][1]) - leftmatrix . D1 . rightmatrix),
 expand (%%),
 matrixmap (cabs, %%),
 maplist (lmax, %%),
 lmax (%%),
 is (%% < 1e-10));
true;

/* from mailing list 2019-05-11: "Problems with gramschmidt" */

(kill(x),
 basis: makelist (x^k, k, 0, 5),
 ip(u,v) := integrate (u*v, x, -1, 1),
 foo: ratsimp (gramschmidt (basis, ip)));
[1,x,(3*x^2-1)/3,(5*x^3-3*x)/5,(35*x^4-30*x^2+3)/35,(63*x^5-70*x^3+15*x)/63]$

bar: map (lambda ([e], ip(e, e)), foo);
[2,2/3,8/45,8/175,128/11025,128/43659]$

(baz: map (lambda ([a, b], a/sqrt(b)), foo, bar),
 genmatrix (lambda ([i, j], ip (baz[i], baz[j])), 5, 5));
matrix ([1, 0, 0, 0, 0],
        [0, 1, 0, 0, 0],
        [0, 0, 1, 0, 0],
        [0, 0, 0, 1, 0],
        [0, 0, 0, 0, 1]);

/* SF bug #3654: "uniteigenvectors fails if uv[1] is used in the user main program." */

(kill(m, mm, r, uv, foo, theta),
 assume (m > 0, r > 0),
 mm:matrix(
          [-(r-2*m)/r,    sqrt(2*m/r),    0,  0],
          [sqrt(2*m/r),   1,  0,  0],
          [0, 0,  r^2,    0],
          [0, 0,  0,  r^2*sin(theta)^2]
      ),
 foo: uniteigenvectors(mm),
 0);
0;

/* go through some gyrations here to verify result of uniteigenvectors */

(kill(S),
 [e1, e2, e3, e4]: [foo[2][1][1], foo[2][2][1], foo[2][3][1], foo[2][4][1]],
 S: transpose (matrix (e1, e2, e3, e4)),
 ratsimp (S . transpose (S)));
matrix ([1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]);

(kill(Lambda),
 Lambda: ident(4),
 for i thru 4 do Lambda[i, i]: foo[1][1][i],
 ratsimp (S . Lambda . transpose (S) - mm));
matrix ([0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]);

/* now test in presence of uv array */

(kill(uv), uv[1]:0);
0;

member ('uv, arrays);
true;

(bar: uniteigenvectors(mm),
 is (bar = foo));
true;

kill(uv);
done;
