Matvec Users’ Guide
Matvec Users' Guide
Matvec Users' Guide
- No tags were found...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
3.4. COMPUTATION 21<br />
This member function is a user-defined function, it’s loaded automatically into memory whenever you<br />
launch <strong>Matvec</strong>.<br />
For example,<br />
> A = [3,2,1;4,5,6;9,8,7];<br />
> A.corrcoef()<br />
covariance<br />
Col 1 Col 2 Col 3<br />
Row 1 1 0.933257 0.741935<br />
Row 2 0.933257 1 0.933257<br />
Row 3 0.741935 0.933257 1<br />
.covariance(B) returns a matrix whose element (i,j) is the covariance between A(i,*) and B(j,*).<br />
For example,<br />
> A = [1,2; 3,4; 5,6];<br />
> B = [6,5; 2,3;8,6];<br />
> A.covariance(B)<br />
det<br />
Col 1 Col 2<br />
Row 1 2 1<br />
Row 2 1 1<br />
A.det() returns the determinant of A based on LU decomposition. Object A remains intact.<br />
diag<br />
A.diag(k), where A is a vector, returns a square matrix of order N+abs(k) with the elements of A on the<br />
k-th diagonal, where N is the size of vector A. k=0 (default) is the main diagonal, k > 0 is above the main<br />
diagonal and k < 0 is below the main diagonal.<br />
A.diag(k), where A is a matrix, returns a vector formed from the elements of the k-th diagonal of A.<br />
A.diag(B,C,D,...), where A,B,C,D,.., are all matrices, returns a block-diagonal matrix with A, B, C, ...<br />
on the diagonal<br />
A.diag().diag() returns a diagonal matrix.<br />
For example,<br />
> c = [1,2;3,4]<br />
Col 1 Col 2<br />
Row 1 1 2<br />
Row 2 3 4<br />
> c.diag()<br />
i = 1 i = 2<br />
1 4<br />
> c.diag().diag()<br />
Col 1 Col 2<br />
Row 1 1 0<br />
Row 2 0 4<br />
> c.diag([5])