Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / adj.cpp
blob19a7a2ee383e15c86edb850bcc0e619ea551c688
1 // Adjunct of a matrix
3 #include "stdafx.h"
4 #include "defs.h"
6 void
7 eval_adj(void)
9 push(cadr(p1));
10 eval();
11 adj();
14 void
15 adj(void)
17 int i, j, n;
19 save();
21 p1 = pop();
23 if (istensor(p1) && p1->u.tensor->ndim == 2 && p1->u.tensor->dim[0] == p1->u.tensor->dim[1])
25 else
26 stop("adj: square matrix expected");
28 n = p1->u.tensor->dim[0];
30 p2 = alloc_tensor(n * n);
32 p2->u.tensor->ndim = 2;
33 p2->u.tensor->dim[0] = n;
34 p2->u.tensor->dim[1] = n;
36 for (i = 0; i < n; i++)
37 for (j = 0; j < n; j++) {
38 cofactor(p1, n, i, j);
39 p2->u.tensor->elem[n * j + i] = pop(); /* transpose */
42 push(p2);
44 restore();