1 (matrix_element_add : "+", matrix_element_mult : "*",0);
4 /*--- ctranspose -----*/
6 (m : matrix([%i,1],[2,%i],[0,2]),0);
10 matrix([-%i,2,0],[1,-%i,2])$
12 zeromatrixp(m - ctranspose(ctranspose(m)));
15 (m : matrix([m,m]),0);
18 (matrix_element_transpose : 'transpose,0);
21 zeromatrixp(ctranspose(mat_unblocker(m)) - mat_unblocker(ctranspose(m)));
24 ctranspose(matrix([%i]));
27 (matrix_element_transpose : false,0);
30 /*--- matrix norm ----*/
32 (m : matrix([2,3],[6,7]), 0);
41 mat_norm(m,'frobenius);
42 sqrt(2^2 + 3^2 + 6^2 + 7^2)$
44 (m : matrix([2*%i,3],[6,7]), 0);
53 mat_norm(m,'frobenius);
54 sqrt(2^2 + 3^2 + 6^2 + 7^2)$
57 /*--- matrix size ----*/
59 matrix_size(matrix([1]));
62 matrix_size(matrix([false],[false]));
65 matrix_size(matrix([false,false]));
68 /*--- matrix linalg_rank and nullity -----*/
70 linalg_rank(matrix([0]));
76 linalg_rank(matrix([1]));
82 linalg_rank(matrix([0,0]));
85 nullity(matrix([0,0]));
88 linalg_rank(matrix([0,1]));
91 nullity(matrix([0,1]));
94 linalg_rank(matrix([0],[0]));
97 nullity(matrix([0],[0]));
100 linalg_rank(matrix([1],[0]));
103 nullity(matrix([1],[0]));
106 linalg_rank(matrix([0],[1]));
109 nullity(matrix([0],[1]));
112 linalg_rank(matrix([1],[1]));
115 nullity(matrix([1],[1]));
118 linalg_rank(matrix([0],[%i]));
121 nullity(matrix([0],[%i]));
124 linalg_rank(matrix([1],[1]));
127 nullity(matrix([1],[1]));
130 linalg_rank(matrix([1],[%i]));
133 nullity(matrix([1],[%i]));
136 linalg_rank(matrix([1,2],[0,0]));
139 nullity(matrix([1,2],[0,0]));
142 linalg_rank(matrix([1,2],[0,1]));
145 nullity(matrix([1,2],[0,1]));
149 /*--- dotproducts ------*/
151 dotproduct(matrix([1]),matrix([1]));
154 dotproduct(matrix([%i]),matrix([%i]));
157 dotproduct(matrix([1],[2]),matrix([-2],[1]));
160 dotproduct(matrix([1],[%i]),matrix([1],[%i]));
163 /*--- matrix nullity ----*/
165 nullity(matrix([0]));
168 nullity(matrix([1]));
171 nullity(matrix([0,0]));
174 nullity(matrix([0,1]));
177 nullity(matrix([1,0]));
180 nullity(matrix([1,2],[0,0]));
183 nullity(matrix([1,2],[0,1]));
186 /*---orthogonal complements ---*/
188 (m : matrix([1,2,3]),0);
191 (s1 : args(columnspace(m)),0);
194 (s2 : args(nullspace(ctranspose(m))),0);
197 every(lambda([e], e=0), map(lambda([e], apply('dotproduct,e)),
198 cartesian_product(setify(s1),setify(s2))));
203 (m : matrix([0,0,3]),0);
206 (s1 : args(columnspace(m)),0);
209 (s2 : args(nullspace(ctranspose(m))),0);
212 every(lambda([e], e=0), map(lambda([e], apply('dotproduct,e)),
213 cartesian_product(setify(s1),setify(s2))));
219 (m : matrix([0,0,0]),0);
222 (s1 : args(columnspace(m)),0);
225 (s2 : args(nullspace(ctranspose(m))),0);
228 every(lambda([e], e=0), map(lambda([e], apply('dotproduct,e)),
229 cartesian_product(setify(s1),setify(s2))));
235 (m : matrix([0,0,3],[0,0,1]),0);
238 (s1 : args(columnspace(m)),0);
241 (s2 : args(nullspace(ctranspose(m))),0);
244 every(lambda([e], e=0), map(lambda([e], apply('dotproduct,e)),
245 cartesian_product(setify(s1),setify(s2))));
251 (m : matrix([1,2,3],[%i,2,1]),0);
254 (s1 : args(columnspace(m)),0);
257 (s2 : args(nullspace(ctranspose(m))),0);
260 every(lambda([e], e=0), map(lambda([e], apply('dotproduct,e)),
261 cartesian_product(setify(s1),setify(s2))));
268 (m : matrix([1,2,3],[%i,2,1],[1,2,3],[1,2,3]),0);
271 (s1 : args(columnspace(m)),0);
274 (s2 : args(nullspace(ctranspose(m))),0);
277 every(lambda([e], e=0), map(lambda([e], expand(apply('dotproduct,e))),
278 cartesian_product(setify(s1),setify(s2))));
284 (m : matrix([1,2,3],[4,5,6],[7,8,9]),0);
287 (s1 : args(columnspace(m)),0);
290 (s2 : args(nullspace(ctranspose(m))),0);
293 every(lambda([e], e=0), map(lambda([e], apply('dotproduct,e)),
294 cartesian_product(setify(s1),setify(s2))));
301 ptriangularize(matrix([1]),z);
304 ptriangularize(matrix([0]),z);
307 ptriangularize(matrix([z]),z);
310 (m : matrix([1,2],[3,4]) - z*ident(2),0);
313 abs(ratsimp(determinant(m) / determinant(ptriangularize(m,z))));
316 (m : matrix([1,2,3],[4,5,6], [7,8,9]) - z*ident(3),0);
319 abs(ratsimp(determinant(m) / determinant(ptriangularize(m,z))));
322 (m : matrix([1-z,2,3-z],[4,5-z,6], [7-z,8,9+z]),0);
325 abs(ratsimp(determinant(m) / determinant(ptriangularize(m,z))));
328 locate_matrix_entry(matrix([1]),1,1,1,1,lambda([e],e # 0), 'bool);
331 locate_matrix_entry(matrix([0]),1,1,1,1,lambda([e],e # 0), 'bool);
334 locate_matrix_entry(matrix([1]),1,1,1,1,identity, 'min);
337 locate_matrix_entry(matrix([1]),1,1,1,1,identity, 'max);
340 locate_matrix_entry(matrix([1,1]),1,1,1,2,identity, 'min);
343 locate_matrix_entry(matrix([1,1]),1,1,1,2,identity, 'max);
346 locate_matrix_entry(matrix([1,2]),1,1,1,2,identity, 'max);
349 locate_matrix_entry(matrix([1,2]),1,1,1,2,identity, 'min);
352 (m : matrix([1,2,3],[4,5,6],[7,8,9]),0);
355 locate_matrix_entry(m,1,1,3,3,lambda([e],e+%pi), min);
358 locate_matrix_entry(m,1,1,3,3,lambda([e],e+%pi), max);
361 locate_matrix_entry(m,1,2,3,3,lambda([e],e+%pi), min);
364 locate_matrix_entry(m,1,2,3,3,lambda([e],e+%pi), max);
367 columnop(matrix([2,1]),1,2,-2);
370 columnop(matrix([2,1]),2,1,x);
373 columnswap(matrix([a,b]),1,2);
376 columnswap(matrix([a,b,c]),2,3);
379 columnswap(columnswap(matrix([a,b],[c,d]),1,2),1,2);
382 ctranspose(matrix([5+%i*6]));
385 ctranspose(matrix([1],[%i]));
388 (load(unwind_protect), unwind_protect((p[1] : 2014, rowop(matrix([a],[b]),1,2,x)), remarray(p)));
391 rowop(matrix([a],[b]),1,2,x);
394 rowswap(rowswap(matrix([a,b],[c,d]),1,2),1,2);
397 (m : matrix([0,1,1],[0,0,0],[0,0,0]),0);
401 ''(funmake('span, sort([matrix([1],[0],[0]),matrix([0],[-1],[1])])))$
404 span(matrix([1],[0],[0]))$
406 zeromatrixp(ctranspose(apply(addcol,args(columnspace(ctranspose(m))))) . apply(addcol,args(nullspace(m))));
409 (m : matrix([0,1,2,3],[0,0,1,0],[0,0,0,0]),0);
412 zeromatrixp(ctranspose(apply(addcol,args(columnspace(ctranspose(m))))) . apply(addcol,args(nullspace(m))));
415 (m : matrix([0,0,2,3],[0,0,1,0],[0,0,0,0]),0);
418 zeromatrixp(ctranspose(apply(addcol,args(columnspace(ctranspose(m))))) . apply(addcol,args(nullspace(m))));
421 (m : matrix([0,0,%i,3],[0,0,%i,0],[0,0,0,0]),0);
424 zeromatrixp(ctranspose(apply(addcol,args(columnspace(ctranspose(m))))) . apply(addcol,args(nullspace(m))));
427 (remvalue(s1,s2,m),0);
431 matrix([1,1/2],[1/2,1/3])$
433 kronecker_product(matrix([a]),matrix([b]));
436 kronecker_product(matrix([1,2],[3,4]),matrix([a,b],[c,d]));
437 ''(mat_unblocker(matrix([matrix([a,b],[c,d]), 2*matrix([a,b],[c,d])],[3*matrix([a,b],[c,d]),4*matrix([a,b],[c,d])])))$
439 every(lambda([e], is(e < 0)), [-1,-2,3]);
442 every(lambda([e], ratnump(e)), [-1,-2,3]);
445 every('bfloatp, matrix([1.3b0,7.8b0],[5.7b0, 9.1b0]));
448 every('bfloatp, matrix([matrix([1.3b0,7.8b0],[5.7b0, 7/8])]));
451 polytocompanion(a*x^3+b*x^2+c*x+d,x);
452 matrix([0,0,-d/a],[1,0,-c/a],[0,1,-b/a])$
454 vandermonde_matrix([a]);
457 vandermonde_matrix([a,b]);
460 vandermonde_matrix([]);
463 /* SF bug #1659985 */
465 vandermonde_matrix([0]);
468 vandermonde_matrix([0,1]);
472 /*--- copylist and copymatrix ----*/
477 (mm : copylist(m),0);
486 (m : matrix([1,2],[3,4]),0);
489 (mm : copymatrix(m),0);
498 /*-- mat_unblocker & friends --*/
500 (m : matrix([0,1],[1,0]),0);
503 (m1 : matrix([m,m],[m,m]),0);
507 matrix([0,1,0,1],[1,0,1,0],[0,1,0,1],[1,0,1,0])$
509 mat_fullunblocker(m1);
510 matrix([0,1,0,1],[1,0,1,0],[0,1,0,1],[1,0,1,0])$
512 (m2 : matrix([m1,m1],[m1,m1]),0);
516 ''(matrix([m,m,m,m],[m,m,m,m],[m,m,m,m],[m,m,m,m]))$
518 mat_fullunblocker(m2);
519 matrix([0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0])$
524 mat_trace(identfor(m1));
527 mat_trace(m1 + identfor(m1));
533 mat_norm(m2,inf) - mat_norm(mat_fullunblocker(m2),inf);
545 blockmatrixp(rat(x));
548 /*---add matrices---*/
550 (m1 : matrix([8,2],[7,4]),0);
553 (m2 : matrix([1,2],[3,42]),0);
556 (m3 : matrix([96,5],[3,42]),0);
559 addmatrices('max,m1,m2,m3);
560 matrix([96,5],[7,42])$
562 addmatrices("+", m1,m2);
563 matrix([9,4],[10,46])$
565 toeplitz([1,2,3],[x,y,z]);
566 matrix([1,y,z],[2,1,y],[3,2,1])$
569 matrix([1,2,3],[2,1,2],[3,2,1])$
571 toeplitz([1,2,3],[x]);
575 matrix([1,2,3],[2,3,0],[3,0,0])$
586 diag_matrix(diag_matrix(1,2),diag_matrix(3,4));
587 matrix([matrix([1,0],[0,2]),matrix([0,0],[0,0])],[matrix([0,0],[0,0]),matrix([3,0],[0,4])])$
589 identfor(diag_matrix(diag_matrix(1,2),diag_matrix(3,4)));
590 ''(diag_matrix(diag_matrix(1,1),diag_matrix(1,1)))$
592 zerofor(diag_matrix(diag_matrix(1,2),diag_matrix(3,4)));
593 ''(diag_matrix(diag_matrix(0,0),diag_matrix(0,0)))$
595 (m : diag_matrix(diag_matrix(5,6),diag_matrix(8,10)),0);
598 mat_norm(m,inf) - mat_norm(mat_unblocker(m),inf);
601 mat_trace(m) - mat_trace(mat_unblocker(m));
605 matrix([1,1/2,1/3],[1/2,1/3,1/4],[1/3,1/4,1/5])$
607 vandermonde_matrix([a,b,c]);
608 matrix([1,a,a^2],[1,b,b^2],[1,c,c^2])$
610 every('integerp, [1,2,3]);
613 every('integerp, []);
616 every('integerp, [1,2,3,x]);
619 every('integerp, [false]);
622 every(lambda([x], is (x < 5)), [4,5,6,7]);
625 errcatch(every('integerp, false));
628 every(lambda([x], is(x < 1932)), matrix([1,2,3],[8,8,74]));
631 (remvalue(mm,m1,m2,m3,m),0);
634 columnspace(matrix([0,1],[0,1]));
635 span(matrix([1],[1]))$
637 linalg_rank(matrix([0,1],[0,1]));
640 sylvester_matrix(0, 0, x);
643 sylvester_matrix(1, 0, x);
646 sylvester_matrix(0, 1, x);
649 sylvester_matrix(1, 1, x);
652 sylvester_matrix(x, 1, x);
655 sylvester_matrix(1, x, x);
658 sylvester_matrix(x, x, x);
661 sylvester_matrix(-x, x, x);
662 matrix([-1,0],[1,0])$
664 sylvester_matrix(a+b*x, x, x);
667 sylvester_matrix(a+b*x, x^2, x);
668 matrix([b,a,0],[0,b,a],[1,0,0])$
670 /* blockmatrixp -- SF bug # 1905668*/
672 blockmatrixp(matrix());
675 blockmatrixp(matrix([]));
678 blockmatrixp(matrix([],[]));
681 blockmatrixp(matrix([false]));
684 blockmatrixp(matrix([matrix()]));
687 blockmatrixp(matrix([matrix([false])]));
690 mat_cond(matrix([1,2,3],[4,5,6],[7,8,10]),1);
693 mat_cond(matrix([1,2,3],[4,5,6],[7,8,10]),inf);
696 /* SF bug #3158: "triangularize gives incorrect result on a matrix containing %i" */
698 nullspace (matrix([0, 1, 1, 0], [-1, 0, 0, 1], [0, 0, 0, 1], [0, 0, -1, 0]) + %i * ident(4));
699 span(matrix([2*%i],[2],[0],[0]));