File: linalg.chapt.txt

package info (click to toggle)
yacas 1.3.6-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 7,176 kB
  • ctags: 3,520
  • sloc: cpp: 13,960; java: 12,602; sh: 11,401; makefile: 552; perl: 517; ansic: 381
file content (1409 lines) | stat: -rw-r--r-- 28,858 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409

			Linear Algebra

*INTRO This chapter describes the commands for doing linear
algebra. They can be used to manipulate vectors, represented as lists,
and matrices, represented as lists of lists.


*CMD Dot, . --- get dot product of tensors
*STD
*CALL
	Dot(t1,t2)
	t1 . t2
Precedence:
*EVAL OpPrecedence(".")

*PARMS

{t1,t2} -- tensor lists (currently only vectors and matrices are supported)

*DESC

{Dot} returns the dot (aka inner) product of two tensors t1 and t2. The last
index of t1 and the first index of t2 are contracted. Currently {Dot} works
only for vectors and matrices. {Dot}-multiplication of two vectors, a matrix
with a vector (and vice versa) or two matrices yields either a scalar, a
vector or a matrix.

*E.G.

	In> Dot({1,2},{3,4})
	Out> 11;
	In> Dot({{1,2},{3,4}},{5,6})
	Out> {17,39};
	In> Dot({5,6},{{1,2},{3,4}})
	Out> {23,34};
	In> Dot({{1,2},{3,4}},{{5,6},{7,8}})
	Out> {{19,22},{43,50}};

	Or, using the "."-Operator:

	In> {1,2} . {3,4}
	Out> 11;
	In> {{1,2},{3,4}} . {5,6}
	Out> {17,39};
	In> {5,6} . {{1,2},{3,4}}
	Out> {23,34};
	In> {{1,2},{3,4}} . {{5,6},{7,8}}
	Out> {{19,22},{43,50}};

*SEE Outer, Cross, IsScalar, IsVector, IsMatrix


*CMD InProduct --- inner product of vectors (deprecated)
*STD
*CALL
	InProduct(a,b)

*PARMS

{a}, {b} -- vectors of equal length

*DESC

The inner product of the two vectors "a" and "b" is returned. The
vectors need to have the same size.

This function is superceded by the {.} operator.

*E.G.

	In> {a,b,c} . {d,e,f};
	Out> a*d+b*e+c*f;

*SEE Dot, CrossProduct

*CMD CrossProduct --- outer product of vectors
*STD
*CALL
	CrossProduct(a,b)
	a X b
Precedence:
*EVAL OpPrecedence("X")

*PARMS

{a}, {b} -- three-dimensional vectors

*DESC

The cross product of the vectors "a"
and "b" is returned. The result is perpendicular to both "a" and
"b" and its length is the product of the lengths of the vectors.
Both "a" and "b" have to be three-dimensional.

*E.G.

	In> {a,b,c} X {d,e,f};
	Out> {b*f-c*e,c*d-a*f,a*e-b*d};

*SEE InProduct





*CMD Outer, o --- get outer tensor product
*STD
*CALL
	Outer(t1,t2)
	t1 o t2
Precedence:
*EVAL OpPrecedence("o")

*PARMS

{t1,t2} -- tensor lists (currently only vectors are supported)

*DESC

{Outer} returns the outer product of two tensors t1 and t2. Currently
{Outer} work works only for vectors, i.e. tensors of rank 1. The outer
product of two vectors yields a matrix.

*E.G.

	In> Outer({1,2},{3,4,5})
	Out> {{3,4,5},{6,8,10}};
	In> Outer({a,b},{c,d})
	Out> {{a*c,a*d},{b*c,b*d}};

	Or, using the "o"-Operator:

	In> {1,2} o {3,4,5}
	Out> {{3,4,5},{6,8,10}};
	In> {a,b} o {c,d}
	Out> {{a*c,a*d},{b*c,b*d}};


*SEE Dot, Cross






*CMD ZeroVector --- create a vector with all zeroes
*STD
*CALL
	ZeroVector(n)

*PARMS

{n} -- length of the vector to return

*DESC

This command returns a vector of length "n", filled with zeroes.

*E.G.

	In> ZeroVector(4)
	Out> {0,0,0,0};

*SEE BaseVector, ZeroMatrix, IsZeroVector

*CMD BaseVector --- base vector
*STD
*CALL
	BaseVector(k, n)

*PARMS

{k} -- index of the base vector to construct

{n} -- dimension of the vector

*DESC

This command returns the "k"-th base vector of dimension "n". This
is a vector of length "n" with all zeroes except for the "k"-th
entry, which contains a 1.

*E.G.

	In> BaseVector(2,4)
	Out> {0,1,0,0};

*SEE ZeroVector, Identity

*CMD Identity --- make identity matrix
*STD
*CALL
	Identity(n)

*PARMS

{n} -- size of the matrix

*DESC

This commands returns the identity matrix of size "n" by "n". This
matrix has ones on the diagonal while the other entries are zero.

*E.G.

	In> Identity(3)
	Out> {{1,0,0},{0,1,0},{0,0,1}};

*SEE BaseVector, ZeroMatrix, DiagonalMatrix

*CMD ZeroMatrix --- make a zero matrix
*STD
*CALL
	ZeroMatrix(n)
	ZeroMatrix(n, m)

*PARMS

{n} -- number of rows

{m} -- number of columns

*DESC

This command returns a matrix with {n} rows and {m} columns,
completely filled with zeroes. If only given one parameter,
it returns the square {n} by {n} zero matrix.

*E.G.

	In> ZeroMatrix(3,4)
	Out> {{0,0,0,0},{0,0,0,0},{0,0,0,0}};
	In> ZeroMatrix(3)
	Out> {{0,0,0},{0,0,0},{0,0,0}};


*SEE ZeroVector, Identity

*CMD Diagonal --- extract the diagonal from a matrix
*STD
*CALL
	Diagonal(A)

*PARMS

{A} -- matrix

*DESC

This command returns a vector of the diagonal components
of the matrix {A}.


*E.G.

	In> Diagonal(5*Identity(4))
	Out> {5,5,5,5};
	In> Diagonal(HilbertMatrix(3))
	Out> {1,1/3,1/5};

*SEE DiagonalMatrix, IsDiagonal

*CMD DiagonalMatrix --- construct a diagonal matrix
*STD
*CALL
	DiagonalMatrix(d)

*PARMS

{d} -- list of values to put on the diagonal

*DESC

This command constructs a diagonal matrix, that is a square matrix
whose off-diagonal entries are all zero. The elements of the vector
"d" are put on the diagonal.

*E.G.

	In> DiagonalMatrix(1 .. 4)
	Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}};

*SEE Identity, ZeroMatrix

*CMD OrthogonalBasis --- create an orthogonal basis 
*STD
*CALL
	OrthogonalBasis(W)

*PARMS

{W} - A linearly independent set of row vectors (aka a matrix)

*DESC

Given a linearly independent set {W} (constructed of rows vectors),
this command returns an orthogonal basis {V} for {W}, which means 
that span(V) = span(W) and {InProduct(V[i],V[j]) = 0} when {i != j}.
This function uses the Gram-Schmidt orthogonalization process.

*E.G.

	In> OrthogonalBasis({{1,1,0},{2,0,1},{2,2,1}}) 
	Out> {{1,1,0},{1,-1,1},{-1/3,1/3,2/3}};


*SEE OrthonormalBasis, InProduct

*CMD OrthonormalBasis --- create an orthonormal basis 
*STD
*CALL
	OrthonormalBasis(W)

*PARMS

{W} - A linearly independent set of row vectors (aka a matrix)

*DESC

Given a linearly independent set {W} (constructed of rows vectors),
this command returns an orthonormal basis {V} for {W}. This is done
by first using {OrthogonalBasis(W)}, then dividing each vector by its
magnitude, so as the give them unit length. 

*E.G.

	In> OrthonormalBasis({{1,1,0},{2,0,1},{2,2,1}})
	Out> {{Sqrt(1/2),Sqrt(1/2),0},{Sqrt(1/3),-Sqrt(1/3),Sqrt(1/3)},
		{-Sqrt(1/6),Sqrt(1/6),Sqrt(2/3)}};

*SEE OrthogonalBasis, InProduct, Normalize




*CMD Normalize --- normalize a vector
*STD
*CALL
	Normalize(v)

*PARMS

{v} -- a vector

*DESC

Return the normalized (unit) vector parallel to {v}: a vector having the same
direction but with length 1.

*E.G.

	In> v:=Normalize({3,4})
	Out> {3/5,4/5};
	In> v . v
	Out> 1;

*SEE InProduct, CrossProduct

*CMD Transpose --- get transpose of a matrix
*STD
*CALL
	Transpose(M)

*PARMS

{M} -- a matrix

*DESC

{Transpose} returns the transpose of a matrix $M$. Because matrices are
just lists of lists, this is a useful operation too for lists.

*E.G.

	In> Transpose({{a,b}})
	Out> {{a},{b}};

*CMD Determinant --- determinant of a matrix
*STD
*CALL
	Determinant(M)

*PARMS

{M} -- a matrix

*DESC

Returns the determinant of a matrix M.

*E.G.

	In> A:=DiagonalMatrix(1 .. 4)
	Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}};
	In> Determinant(A)
	Out> 24;

*CMD Trace --- trace of a matrix
*STD
*CALL
	Trace(M)

*PARMS

{M} -- a matrix

*DESC

{Trace} returns the trace of a matrix $M$ (defined as the sum of the
elements on the diagonal of the matrix).

*E.G.

	In> A:=DiagonalMatrix(1 .. 4)
	Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}};
	In> Trace(A)
	Out> 10;

*CMD Inverse --- get inverse of a matrix
*STD
*CALL
	Inverse(M)

*PARMS

{M} -- a matrix

*DESC

Inverse returns the inverse of matrix $M$. The determinant of $M$ should
be non-zero. Because this function uses {Determinant} for calculating
the inverse of a matrix, you can supply matrices with non-numeric (symbolic)
matrix elements.

*E.G.

	In> A:=DiagonalMatrix({a,b,c})
	Out> {{a,0,0},{0,b,0},{0,0,c}};
	In> B:=Inverse(A)
	Out> {{(b*c)/(a*b*c),0,0},{0,(a*c)/(a*b*c),0},
	{0,0,(a*b)/(a*b*c)}};
	In> Simplify(B)
	Out> {{1/a,0,0},{0,1/b,0},{0,0,1/c}};

*SEE Determinant

*CMD Minor --- get principal minor of a matrix
*STD
*CALL
	Minor(M,i,j)

*PARMS

{M} -- a matrix

{i}, {j} - positive integers

*DESC

Minor returns the minor of a matrix around
the element ($i$, $j$). The minor is the determinant of the matrix obtained from $M$ by
deleting the $i$-th row and the $j$-th column.

*E.G.

	In> A := {{1,2,3}, {4,5,6}, {7,8,9}};
	Out> {{1,2,3},{4,5,6},{7,8,9}};
	In> PrettyForm(A);
	
	/                    \
	| ( 1 ) ( 2 ) ( 3 )  |
	|                    |
	| ( 4 ) ( 5 ) ( 6 )  |
	|                    |
	| ( 7 ) ( 8 ) ( 9 )  |
	\                    /
	Out> True;
	In> Minor(A,1,2);
	Out> -6;
	In> Determinant({{2,3}, {8,9}});
	Out> -6;

*SEE CoFactor, Determinant, Inverse

*CMD CoFactor --- cofactor of a matrix
*STD
*CALL
	CoFactor(M,i,j)

*PARMS

{M} -- a matrix

{i}, {j} - positive integers

*DESC

{CoFactor} returns the cofactor of a matrix around
the element ($i$, $j$). The cofactor is the minor times
$(-1)^(i+j)$.

*E.G.

	In> A := {{1,2,3}, {4,5,6}, {7,8,9}};
	Out> {{1,2,3},{4,5,6},{7,8,9}};
	In> PrettyForm(A);
	
	/                    \
	| ( 1 ) ( 2 ) ( 3 )  |
	|                    |
	| ( 4 ) ( 5 ) ( 6 )  |
	|                    |
	| ( 7 ) ( 8 ) ( 9 )  |
	\                    /
	Out> True;
	In> CoFactor(A,1,2);
	Out> 6;
	In> Minor(A,1,2);
	Out> -6;
	In> Minor(A,1,2) * (-1)^(1+2);
	Out> 6;

*SEE Minor, Determinant, Inverse


*CMD MatrixPower --- get nth power of a square matrix
*STD
*CALL
	MatrixPower(mat,n)

*PARMS

{mat} -- a square matrix

{n} -- an integer

*DESC

{MatrixPower(mat,n)} returns the {n}th power of a square matrix {mat}. For
positive {n} it evaluates dot products of {mat} with itself. For negative
{n} the nth power of the inverse of {mat} is returned. For {n}=0 the identity
matrix is returned.

*EG
	In> A:={{1,2},{3,4}}
	Out> {{1,2},{3,4}};
	In> MatrixPower(A,0)
	Out> {{1,0},{0,1}};
	In> MatrixPower(A,1)
	Out> {{1,2},{3,4}};
	In> MatrixPower(A,3)
	Out> {{37,54},{81,118}};
	In> MatrixPower(A,-3)
	Out> {{-59/4,27/4},{81/8,-37/8}};

*SEE IsSquareMatrix, Inverse, Dot


*CMD SolveMatrix --- solve a linear system
*STD
*CALL
	SolveMatrix(M,v)

*PARMS

{M} -- a matrix

{v} -- a vector

*DESC

{SolveMatrix} returns the vector $x$ that satisfies
the equation $M*x = v$. The determinant of $M$ should be non-zero.

*E.G.

	In> A := {{1,2}, {3,4}};
	Out> {{1,2},{3,4}};
	In> v := {5,6};
	Out> {5,6};
	In> x := SolveMatrix(A, v);
	Out> {-4,9/2};
	In> A * x;
	Out> {5,6};

*SEE Inverse, Solve, PSolve, Determinant

*CMD CharacteristicEquation --- get characteristic polynomial of a matrix
*STD
*CALL
	CharacteristicEquation(matrix,var)

*PARMS

{matrix} -- a matrix

{var} -- a free variable

*DESC

CharacteristicEquation
returns the characteristic equation of "matrix", using
"var". The zeros of this equation are the eigenvalues
of the matrix, Det(matrix-I*var);

*E.G.

	In> A:=DiagonalMatrix({a,b,c})
	Out> {{a,0,0},{0,b,0},{0,0,c}};
	In> B:=CharacteristicEquation(A,x)
	Out> (a-x)*(b-x)*(c-x);
	In> Expand(B,x)
	Out> (b+a+c)*x^2-x^3-((b+a)*c+a*b)*x+a*b*c;

*SEE EigenValues, EigenVectors

*CMD EigenValues --- get eigenvalues of a matrix
*STD
*CALL
	EigenValues(matrix)

*PARMS

{matrix} -- a square matrix

*DESC

EigenValues returns the eigenvalues of a matrix.
The eigenvalues x of a matrix M are the numbers such that
$M*v=x*v$ for some vector.

It first determines the characteristic equation, and then factorizes this
equation, returning the roots of the characteristic equation
Det(matrix-x*identity).

*E.G.

	In> M:={{1,2},{2,1}}
	Out> {{1,2},{2,1}};
	In> EigenValues(M)
	Out> {3,-1};

*SEE EigenVectors, CharacteristicEquation

*CMD EigenVectors --- get eigenvectors of a matrix
*STD
*CALL
	EigenVectors(A,eigenvalues)

*PARMS

{matrix} -- a square matrix

{eigenvalues} -- list of eigenvalues as returned by {EigenValues}

*DESC

{EigenVectors} returns a list of the eigenvectors of a matrix.
It uses the eigenvalues and the matrix to set up n equations with
n unknowns for each eigenvalue, and then calls {Solve} to determine
the values of each vector.

*E.G.

	In> M:={{1,2},{2,1}}
	Out> {{1,2},{2,1}};
	In> e:=EigenValues(M)
	Out> {3,-1};
	In> EigenVectors(M,e)
	Out> {{-ki2/ -1,ki2},{-ki2,ki2}};

*SEE EigenValues, CharacteristicEquation




*CMD Sparsity --- get the sparsity of a matrix
*STD
*CALL
	Sparsity(matrix)
*PARMS

{matrix} -- a matrix

*DESC

The function {Sparsity} returns a number between {0} and {1} which 
represents the percentage of zero entries in the matrix. Although
there is no definite critical value, a sparsity of {0.75}  or more
is almost universally considered a "sparse" matrix. These type of
matrices can be handled in a different manner than "full" matrices
which speedup many calculations by orders of magnitude.

*E.G.

	In> Sparsity(Identity(2))
	Out> 0.5;
	In> Sparsity(Identity(10))
	Out> 0.9;
	In> Sparsity(HankelMatrix(10))
	Out> 0.45;
	In> Sparsity(HankelMatrix(100))
	Out> 0.495;
	In> Sparsity(HilbertMatrix(10))
	Out> 0;
	In> Sparsity(ZeroMatrix(10,10))
	Out> 1;


*CMD Cholesky --- find the Cholesky Decomposition
*STD
*CALL
	Cholesky(A)

*PARMS

{A} -- a square positive definite matrix

*DESC

{Cholesky} returns a upper triangular matrix {R} such that {Transpose(R)*R = A}.
The matrix {A} must be positive definite, {Cholesky} will notify the user if the matrix
is not. Some families of positive definite matrices are all symmetric matrices, diagonal
matrices with positive elements and Hilbert matrices.

*E.G.

	In> A:={{4,-2,4,2},{-2,10,-2,-7},{4,-2,8,4},{2,-7,4,7}}
	Out> {{4,-2,4,2},{-2,10,-2,-7},{4,-2,8,4},{2,-7,4,7}};
	In> R:=Cholesky(A);
	Out> {{2,-1,2,1},{0,3,0,-2},{0,0,2,1},{0,0,0,1}};
	In> Transpose(R)*R = A
	Out> True;
	In> Cholesky(4*Identity(5))
	Out> {{2,0,0,0,0},{0,2,0,0,0},{0,0,2,0,0},{0,0,0,2,0},{0,0,0,0,2}};
	In> Cholesky(HilbertMatrix(3))
	Out> {{1,1/2,1/3},{0,Sqrt(1/12),Sqrt(1/12)},{0,0,Sqrt(1/180)}};
	In> Cholesky(ToeplitzMatrix({1,2,3}))
	In function "Check" :
	CommandLine(1) : "Cholesky: Matrix is not positive definite"

*SEE IsSymmetric, IsDiagonal, Diagonal


			Predicates related to matrices


*CMD IsScalar --- test for a scalar
*STD
*CALL

	IsScalar(expr)

*PARMS

{expr} -- a mathematical object

*DESC

{IsScalar} returns {True} if {expr} is a scalar, {False} otherwise.
Something is considered to be a scalar if it's not a list.

*E.G.
	In> IsScalar(7)
	Out> True;
	In> IsScalar(Sin(x)+x)
	Out> True;
	In> IsScalar({x,y})
	Out> False;

*SEE IsList, IsVector, IsMatrix


*CMD IsVector --- test for a vector
*STD
*CALL

	IsVector(expr)

	IsVector(pred,expr)

*PARMS

{expr} -- expression to test

{pred} -- predicate test (e.g. IsNumber, IsInteger, ...)

*DESC

{IsVector(expr)} returns {True} if {expr} is a vector, {False} otherwise.
Something is considered to be a vector if it's a list of scalars.
{IsVector(pred,expr)} returns {True} if {expr} is a vector and if the
predicate test {pred} returns {True} when applied to every element of
the vector {expr}, {False} otherwise.

*E.G.
	In> IsVector({a,b,c})
	Out> True;
	In> IsVector({a,{b},c})
	Out> False;
	In> IsVector(IsInteger,{1,2,3})
	Out> True;
	In> IsVector(IsInteger,{1,2.5,3})
	Out> False;

*SEE IsList, IsScalar, IsMatrix


*CMD IsMatrix --- test for a matrix
*STD
*CALL
	IsMatrix(expr)

	IsMatrix(pred,expr)

*PARMS

{expr} -- expression to test

{pred} -- predicate test (e.g. IsNumber, IsInteger, ...)

*DESC

{IsMatrix(expr)} returns {True} if {expr} is a matrix, {False} otherwise.
Something is considered to be a matrix if it's a list of vectors of equal
length.
{IsMatrix(pred,expr)} returns {True} if {expr} is a matrix and if the
predicate test {pred} returns {True} when applied to every element of
the matrix {expr}, {False} otherwise.

*E.G.

	In> IsMatrix(1)
	Out> False;
	In> IsMatrix({1,2})
	Out> False;
	In> IsMatrix({{1,2},{3,4}})
	Out> True;
	In> IsMatrix(IsRational,{{1,2},{3,4}})
	Out> False;
	In> IsMatrix(IsRational,{{1/2,2/3},{3/4,4/5}})
	Out> True;

*SEE IsList, IsVector


*CMD IsSquareMatrix --- test for a square matrix
*STD
*CALL
	IsSquareMatrix(expr)

	IsSquareMatrix(pred,expr)

*PARMS

{expr} -- expression to test

{pred} -- predicate test (e.g. IsNumber, IsInteger, ...)

*DESC

{IsSquareMatrix(expr)} returns {True} if {expr} is a square matrix,
{False} otherwise. Something is considered to be a square matrix if
it's a matrix having the same number of rows and columns.
{IsMatrix(pred,expr)} returns {True} if {expr} is a square matrix and
if the predicate test {pred} returns {True} when applied to every
element of the matrix {expr}, {False} otherwise.

*E.G.

	In> IsSquareMatrix({{1,2},{3,4}});
	Out> True;
	In> IsSquareMatrix({{1,2,3},{4,5,6}});
	Out> False;
	In> IsSquareMatrix(IsBoolean,{{1,2},{3,4}});
	Out> False;
	In> IsSquareMatrix(IsBoolean,{{True,False},{False,True}});
	Out> True;

*SEE IsMatrix

*CMD IsHermitian --- test for a Hermitian matrix
*STD
*CALL
	IsHermitian(A)

*PARMS

{A} -- a square matrix

*DESC

IsHermitian(A) returns {True} if {A} is Hermitian and {False}
otherwise. $A$ is a Hermitian matrix iff Conjugate( Transpose $A$ )=$A$.
If $A$ is a real matrix, it must be symmetric to be Hermitian.

*E.G.

	In> IsHermitian({{0,I},{-I,0}})
	Out> True;
	In> IsHermitian({{0,I},{2,0}})
	Out> False;

*SEE IsUnitary

*CMD IsOrthogonal --- test for an orthogonal matrix
*STD
*CALL
	IsOrthogonal(A)

*PARMS

{A} -- square matrix

*DESC

{IsOrthogonal(A)} returns {True} if {A} is orthogonal and {False} 
otherwise. $A$ is orthogonal iff $A$*Transpose($A$) = Identity, or
equivalently Inverse($A$) = Transpose($A$).

*E.G.

	In> A := {{1,2,2},{2,1,-2},{-2,2,-1}};
	Out> {{1,2,2},{2,1,-2},{-2,2,-1}};
	In> PrettyForm(A/3)

	/                      \
	| / 1 \  / 2 \ / 2 \   |
	| | - |  | - | | - |   |
	| \ 3 /  \ 3 / \ 3 /   |
	|                      |
	| / 2 \  / 1 \ / -2 \  |
	| | - |  | - | | -- |  |
	| \ 3 /  \ 3 / \ 3  /  |
	|                      |
	| / -2 \ / 2 \ / -1 \  |
	| | -- | | - | | -- |  |
	| \ 3  / \ 3 / \ 3  /  |
	\                      /
	Out> True;
	In> IsOrthogonal(A/3)
	Out> True;

*CMD IsDiagonal --- test for a diagonal matrix
*STD
*CALL
	IsDiagonal(A)

*PARMS

{A} -- a matrix

*DESC

{IsDiagonal(A)} returns {True} if {A} is a diagonal square matrix and {False} otherwise.

*E.G.
	In> IsDiagonal(Identity(5))
	Out> True;
	In> IsDiagonal(HilbertMatrix(5))
	Out> False;

*CMD IsLowerTriangular --- test for a lower triangular matrix
*CMD IsUpperTriangular --- test for an upper triangular matrix
*STD
*CALL
	IsLowerTriangular(A)
	IsUpperTriangular(A)

*PARMS

{A} -- a matrix

*DESC

A lower/upper triangular matrix is a square matrix which has all zero entries above/below the diagonal.

{IsLowerTriangular(A)} returns {True} if {A} is a lower triangular matrix and {False} otherwise.
{IsUpperTriangular(A)} returns {True} if {A} is an upper triangular matrix and {False} otherwise.

*E.G.
	In> IsUpperTriangular(Identity(5))
	Out> True;
	In> IsLowerTriangular(Identity(5))
	Out> True;
	In> IsLowerTriangular({{1,2},{0,1}})
	Out> False;
	In> IsUpperTriangular({{1,2},{0,1}})
	Out> True;
A non-square matrix cannot be triangular:
	In> IsUpperTriangular({{1,2,3},{0,1,2}})
	Out> False;

*SEE IsDiagonal

*CMD IsSymmetric --- test for a symmetric matrix
*STD
*CALL
	IsSymmetric(A)

*PARMS

{A} -- a matrix

*DESC

{IsSymmetric(A)} returns {True} if {A} is symmetric and {False} otherwise.
$A$ is symmetric iff Transpose ($A$) =$A$.

*E.G.

	In> A := {{1,0,0,0,1},{0,2,0,0,0},{0,0,3,0,0},
	  {0,0,0,4,0},{1,0,0,0,5}};
	In> PrettyForm(A)

	/                                \
	| ( 1 ) ( 0 ) ( 0 ) ( 0 ) ( 1 )  |
	|                                |
	| ( 0 ) ( 2 ) ( 0 ) ( 0 ) ( 0 )  |
	|                                |
	| ( 0 ) ( 0 ) ( 3 ) ( 0 ) ( 0 )  |
	|                                |
	| ( 0 ) ( 0 ) ( 0 ) ( 4 ) ( 0 )  |
	|                                |
	| ( 1 ) ( 0 ) ( 0 ) ( 0 ) ( 5 )  |
	\                                /
	Out> True;
	In> IsSymmetric(A)
	Out> True;
		

*SEE IsHermitian, IsSkewSymmetric

*CMD IsSkewSymmetric --- test for a skew-symmetric matrix
*STD
*CALL
	IsSkewSymmetric(A)

*PARMS

{A} -- a square matrix

*DESC

{IsSkewSymmetric(A)} returns {True} if {A} is skew symmetric and {False} otherwise.
$A$ is skew symmetric iff $Transpose(A)$ =$-A$. 

*E.G.

	In> A := {{0,-1},{1,0}}
	Out> {{0,-1},{1,0}};
	In> PrettyForm(%)

	/               \
	| ( 0 ) ( -1 )  |
	|               |
	| ( 1 ) ( 0 )   |
	\               /
	Out> True;
	In> IsSkewSymmetric(A);
	Out> True;

*SEE IsSymmetric, IsHermitian
 
*CMD IsUnitary --- test for a unitary matrix
*STD
*CALL
	IsUnitary(A)

*PARMS

{A} -- a square matrix

*DESC

This function tries to find out if A is unitary.

A matrix $A$ is orthogonal iff $A^(-1)$ = Transpose( Conjugate($A$) ). This is
equivalent to the fact that the columns of $A$ build an orthonormal system
(with respect to the scalar product defined by {InProduct}).

*E.G.

	In> IsUnitary({{0,I},{-I,0}})
	Out> True;
	In> IsUnitary({{0,I},{2,0}})
	Out> False;

*SEE IsHermitian, IsSymmetric

*CMD IsIdempotent --- test for an idempotent matrix
*STD
*CALL
	IsIdempotent(A)

*PARMS

{A} -- a square matrix

*DESC

{IsIdempotent(A)} returns {True} if {A} is idempotent and {False} otherwise.
$A$ is idempotent iff $A^2=A$. Note that this also implies that $A$ raised
to any power is also equal to $A$.

*E.G.

	In> IsIdempotent(ZeroMatrix(10,10));
	Out> True;
	In> IsIdempotent(Identity(20))
	Out> True;


			Special matrices


*CMD JacobianMatrix --- calculate the Jacobian matrix of $n$ functions in $n$ variables
*STD
*CALL
	JacobianMatrix(functions,variables)

*PARMS

{functions} -- an $n$-dimensional vector of functions

{variables} -- an $n$-dimensional vector of variables

*DESC

The function {JacobianMatrix} calculates the Jacobian matrix
of n functions in n variables.

The ($i$,$j$)-th element of the Jacobian matrix is defined as the derivative
of $i$-th function with respect to the $j$-th variable.

*E.G.

	In> JacobianMatrix( {Sin(x),Cos(y)}, {x,y} ); 
	Out> {{Cos(x),0},{0,-Sin(y)}};
	In> PrettyForm(%)

	/                                 \
	| ( Cos( x ) ) ( 0 )              |
	|                                 |
	| ( 0 )        ( -( Sin( y ) ) )  |
	\                                 /


*CMD VandermondeMatrix --- create the Vandermonde matrix
*STD
*CALL
	VandermondeMatrix(vector)
*PARMS

{vector} -- an $n$-dimensional vector 

*DESC

The function {VandermondeMatrix} calculates the Vandermonde matrix
of a vector.

The ($i$,$j$)-th element of the Vandermonde matrix is defined as $i^(j-1)$.

*E.G.
	In> VandermondeMatrix({1,2,3,4})
	Out> {{1,1,1,1},{1,2,3,4},{1,4,9,16},{1,8,27,64}};
	In>PrettyForm(%)

	/                            \
	| ( 1 ) ( 1 ) ( 1 )  ( 1 )   |
	|                            |
	| ( 1 ) ( 2 ) ( 3 )  ( 4 )   |
	|                            |
	| ( 1 ) ( 4 ) ( 9 )  ( 16 )  |
	|                            |
	| ( 1 ) ( 8 ) ( 27 ) ( 64 )  |
	\                            /

*CMD HessianMatrix --- create the Hessian matrix
*STD
*CALL
	HessianMatrix(function,var)
*PARMS

{function} -- a function in $n$ variables

{var} -- an $n$-dimensional vector of variables

*DESC

The function {HessianMatrix} calculates the Hessian matrix
of a vector.

If $f(x)$ is a function of an $n$-dimensional vector $x$, then the ($i$,$j$)-th element of the Hessian matrix of the function $f(x)$ is defined as 
$ Deriv(x[i]) Deriv(x[j]) f(x) $. If the third
order mixed partials are continuous, then the Hessian
matrix is symmetric (a standard theorem of calculus).

The Hessian matrix is used in the second derivative test 
to discern if a critical point is a local maximum, a local
minimum or a saddle point.


*E.G.

	In> HessianMatrix(3*x^2-2*x*y+y^2-8*y, {x,y} )
	Out> {{6,-2},{-2,2}};
	In> PrettyForm(%)

	/                \
	| ( 6 )  ( -2 )  |
	|                |
	| ( -2 ) ( 2 )   |
	\                /


*CMD HilbertMatrix --- create a Hilbert matrix
*STD
*CALL
	HilbertMatrix(n)
	HilbertMatrix(n,m)
*PARMS

{n,m} -- positive integers

*DESC

The function {HilbertMatrix} returns the {n} by {m} Hilbert matrix
if given two arguments, and the square {n} by {n} Hilbert matrix
if given only one. The Hilbert matrix is defined as {A(i,j) = 1/(i+j-1)}.
The Hilbert matrix is extremely sensitive to manipulate and invert numerically.

*E.G.

	In> PrettyForm(HilbertMatrix(4))

	/                          \
	| ( 1 ) / 1 \ / 1 \ / 1 \  |
	|       | - | | - | | - |  |
	|       \ 2 / \ 3 / \ 4 /  |
	|                          |
	| / 1 \ / 1 \ / 1 \ / 1 \  |
	| | - | | - | | - | | - |  |
	| \ 2 / \ 3 / \ 4 / \ 5 /  |
	|                          |
	| / 1 \ / 1 \ / 1 \ / 1 \  |
	| | - | | - | | - | | - |  |
	| \ 3 / \ 4 / \ 5 / \ 6 /  |
	|                          |
	| / 1 \ / 1 \ / 1 \ / 1 \  |
	| | - | | - | | - | | - |  |
	| \ 4 / \ 5 / \ 6 / \ 7 /  |
	\                          /

*SEE HilbertInverseMatrix

*CMD HilbertInverseMatrix --- create a Hilbert inverse matrix
*STD
*CALL
	HilbertInverseMatrix(n)
*PARMS

{n} -- positive integer

*DESC

The function {HilbertInverseMatrix} returns the {n} by {n} inverse of the
corresponding Hilbert matrix. All Hilbert inverse matrices have integer
entries that grow in magnitude rapidly.

*E.G.
	In> PrettyForm(HilbertInverseMatrix(4))

	/                                         \
	| ( 16 )   ( -120 )  ( 240 )   ( -140 )   |
	|                                         |
	| ( -120 ) ( 1200 )  ( -2700 ) ( 1680 )   |
	|                                         |
	| ( 240 )  ( -2700 ) ( 6480 )  ( -4200 )  |
	|                                         |
	| ( -140 ) ( 1680 )  ( -4200 ) ( 2800 )   |
	\                                         /

*SEE HilbertMatrix


*CMD ToeplitzMatrix --- create a Toeplitz matrix
*STD
*CALL
	ToeplitzMatrix(N)
*PARMS

{N} -- an $n$-dimensional row vector

*DESC

The function {ToeplitzMatrix} calculates the Toeplitz matrix given
an $n$-dimensional row vector. This matrix has the same entries in
all diagonal columns, from upper left to lower right.

*E.G.

	In> PrettyForm(ToeplitzMatrix({1,2,3,4,5}))

	/                                \
	| ( 1 ) ( 2 ) ( 3 ) ( 4 ) ( 5 )  |
	|                                |
	| ( 2 ) ( 1 ) ( 2 ) ( 3 ) ( 4 )  |
	|                                |
	| ( 3 ) ( 2 ) ( 1 ) ( 2 ) ( 3 )  |
	|                                |
	| ( 4 ) ( 3 ) ( 2 ) ( 1 ) ( 2 )  |
	|                                |
	| ( 5 ) ( 4 ) ( 3 ) ( 2 ) ( 1 )  |
	\                                /


*CMD WronskianMatrix --- create the Wronskian matrix
*STD
*CALL
	WronskianMatrix(func,var)
*PARMS

{func} -- an $n$-dimensional vector of functions

{var} -- a variable to differentiate with respect to

*DESC

The function {WronskianMatrix} calculates the Wronskian matrix
of $n$ functions.

The Wronskian matrix is created by putting each function as the
first element of each column, and filling in the rest of each
column by the ($i-1$)-th derivative, where $i$ is the current row.

The Wronskian matrix is used to verify that the $n$ functions are linearly
independent, usually solutions to a differential equation.
If the determinant of the Wronskian matrix is zero, then the functions
are dependent, otherwise they are independent.

*E.G.
	In> WronskianMatrix({Sin(x),Cos(x),x^4},x);
	Out> {{Sin(x),Cos(x),x^4},{Cos(x),-Sin(x),4*x^3},
	  {-Sin(x),-Cos(x),12*x^2}};
	In> PrettyForm(%)

	/                                                 \
	| ( Sin( x ) )      ( Cos( x ) )      /  4 \      |
	|                                     \ x  /      |
	|                                                 |
	| ( Cos( x ) )      ( -( Sin( x ) ) ) /      3 \  |
	|                                     \ 4 * x  /  |
	|                                                 |
	| ( -( Sin( x ) ) ) ( -( Cos( x ) ) ) /       2 \ |
	|                                     \ 12 * x  / |
	\                                                 /
The last element is a linear combination of the first two, so the determinant is zero:
	In> A:=Determinant( WronskianMatrix( {x^4,x^3,2*x^4 
	  + 3*x^3},x ) )
	Out> x^4*3*x^2*(24*x^2+18*x)-x^4*(8*x^3+9*x^2)*6*x
	  +(2*x^4+3*x^3)*4*x^3*6*x-4*x^6*(24*x^2+18*x)+x^3
	  *(8*x^3+9*x^2)*12*x^2-(2*x^4+3*x^3)*3*x^2*12*x^2;
	In> Simplify(A)
	Out> 0;


*CMD SylvesterMatrix --- calculate the Sylvester matrix of two polynomials
*STD
*CALL
	SylvesterMatrix(poly1,poly2,variable)

*PARMS

{poly1} -- polynomial

{poly2} -- polynomial

{variable} -- variable to express the matrix for

*DESC

The function {SylvesterMatrix} calculates the Sylvester matrix
for a pair of polynomials.

The Sylvester matrix is closely related to the resultant, which
is defined as the determinant of the Sylvester matrix. Two polynomials
share common roots only if the resultant is zero.

*E.G.

	In> ex1:= x^2+2*x-a
	Out> x^2+2*x-a;
	In> ex2:= x^2+a*x-4
	Out> x^2+a*x-4;
	In> A:=SylvesterMatrix(ex1,ex2,x)
	Out> {{1,2,-a,0},{0,1,2,-a},
	  {1,a,-4,0},{0,1,a,-4}};
	In> B:=Determinant(A)
	Out> 16-a^2*a- -8*a-4*a+a^2- -2*a^2-16-4*a;
	In> Simplify(B)
	Out> 3*a^2-a^3;

The above example shows that the two polynomials have common
zeros if $ a = 3 $.

*SEE Determinant, Simplify, Solve, PSolve