Skip to content

Commit 4dfe174

Browse files
Update matrix.mac
Improvements to `aug` following suggestions from Marc Peterfi. The function behaves as it previously did when given a single matrix (that is, it will insert a vertical bar before the final column), but when given two or more matrices as arguments it will concatenate them with vertical bars between each. The original use case is to generate worked solutions for matrix inversion or similar, e.g. aug(A, ident(3)) → aug(rowop(A,2,1,A[2,1]/A[1,1]), rowop(ident(3),2,1,A[2,1]/A[1,1]) but could be used for more. aug(addcol(A,b)) and aug(A,b) are identical. Existing test cases will fail only because the vertical bar is now generated as a closing bracket instead of an opening one. This looks nicer, so I am treating this as a feature instead of a bug.
1 parent c16b364 commit 4dfe174

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

stack/maxima/contrib/matrix.mac

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,43 @@ stack_linear_algebra_declare(true)$
2828
/*******************************************************************************/
2929
/* A convenience function for displaying a matrix as an augmented matrix */
3030
/*******************************************************************************/
31-
texput(aug_matrix, lambda([ex], block([M,ll,rr,m,n,A,b,simp],
32-
simp:true,
33-
M: apply(matrix,args(ex)),
34-
ll: lmxchar,
35-
if is(ll="[") then rr: "]"
36-
else if is(ll="(") then rr: ")"
37-
else if is(ll="") then (ll: ".", rr: ".")
38-
else if is(ll="{") then (ll: "\\{", rr: "\\}")
39-
else if is(ll="|") then rr: "|",
40-
[m, n]: matrix_size(M),
41-
A: submatrix(M,n),
42-
b: col(M,n),
43-
sconcat("\\left",ll,block([lmxchar],lmxchar:"",tex1(A)),"\\right|\\left.",block([lmxchar],lmxchar:"",tex1(b)),"\\right",rr)
44-
)));
31+
texput(aug_matrix, lambda([ex],
32+
block([exl:args(ex),ii,ss,ll:lmxchar,rr,lmxchar],
33+
if is(ll="[") then rr: "]"
34+
else if is(ll="(") then rr: ")"
35+
else if is(ll="") then (ll: ".", rr: ".")
36+
else if is(ll="{") then (ll: "\\{", rr: "\\}")
37+
else if is(ll="|") then rr: "|",
38+
lmxchar: "",
39+
ss: ["\\left",ll,tex1(exl[1])],
40+
for ii: 2 thru length(exl) do block(
41+
ii: ev(ii,simp),
42+
ss: append(ss, ["\\left|",tex1(exl[ii]),"\\right."])
43+
),
44+
ss: append(ss, ["\\right",rr]),
45+
return(simplode(ss))
46+
)
47+
));
4548

4649
/**
4750
* Converts a matrix to an aug_matrix
4851
* aug_matrix is an inert function that is used for displaying a matrix as an augmented matrix
4952
* To convert back, use de_aug
5053
*
51-
* @param[matrix] M The matrix you would like to display as an augmented matrix
54+
* @param[matrix] M The matrix or matrices you would like to display as an augmented matrix
5255
* @return[aug_matrix] An augmented matrix
5356
*/
54-
aug(M):= apply(aug_matrix,args(M));
57+
aug([M]):= if is(length(M)=1) then apply(aug_matrix,[submatrix(first(M),second(matrix_size(first(M)))),col(first(M),second(matrix_size(first(M))))]) else apply(aug_matrix,M);
5558

5659
/**
5760
* Converts an aug_matrix to a matrix
5861
* aug_matrix is an inert function that is used for displaying a matrix as an augmented matrix
62+
* Note: This always returns a single matrix constructed by concatenating the arguments of the original aug_matrix.
5963
*
6064
* @param[matrix] M The aug_matrix you would like to treat as a regular matrix
6165
* @return[aug_matrix] A matrix
6266
*/
63-
de_aug(M):= apply(matrix,args(M));
67+
de_aug(M):= apply(addcol, args(M));
6468

6569
/*********************************************************************************/
6670
/* Functions to extract parts of matrices */

0 commit comments

Comments
 (0)