In: Advanced Math
Use Octave
Given a matrix M ∈ M mn , each function should first ensure that
the matrix has the proper size (e.g., be
square if the definition involves a square matrix). Until CA4, we
do not implement proper error handling,
so for now, if the matrix is not of the proper size, the function
should return FALSE. In this assignment,
we create functions that characterise matrix properties or types.
These definitions can be found easily. For
reference, the location of some of the definitions in the Horn
& Johnson book is provided. The following
functions should be made available:
1. is_ real _matrix(M) is true if M ∈ M(R).
2. is _complex _matrix(M) is true if M ∈ M(C) and ∃i,j such that
=(m ij ) 6= 0.
3. is _diagonal_ matrix(M) is true if M ∈ M(C) is a diagonal matrix
(H&J 0.9.1).
4. is_ lower _triangular_ matrix(M) is true if M ∈ M(C) is a lower
triangular matrix (H&J 0.9.3).
5. is _upper _triangular_ matrix(M) is true if M ∈ M(C) is an upper
triangular matrix (H&J 0.9.3).
6. is _triangular _matrix(M) is true if M ∈ M(C) is a triangular
matrix (H&J 0.9.3).
7. is _symmetric_ matrix(M) is true if M ∈ M(C) is a symmetric
matrix.
8. is -hermitian _matrix(M) is true if M ∈ M(C) is a Hermitian
matrix.
9. is_ skew _hermitian _matrix(M) is true if M ∈ M(C) is a skew
Hermitian matrix.
10. is_ normal _matrix(M) is true if M ∈ M(C) is a normal
matrix.
11. is _unitary_ matrix(M) is true if M ∈ M(C) is a unitary
matrix.
12. is_ orthogonal_ matrix(M) is true if M ∈ M(C) is an orthogonal
matrix.
13. is_ permutation _matrix(M) is true if M ∈ M(C) is a permutation
matrix (H&J 0.9.5).
14. is _reversal_ matrix(M) is true if M ∈ M(C) is a reversal
matrix (H&J 0.9.5).
15. is _circulant _matrix(M) is true if M ∈ M(C) is a circulant
matrix (H&J 0.9.6).
16. is _Toeplitz_ matrix(M) is true if M ∈ M(C) is a Toeplitz
matrix (H&J 0.9.7).
17. is _Hankel _matrix(M) is true if M ∈ M(C) is a Hankel matrix
(H&J 0.9.8).
18. is _lower_ Hessenberg matrix(M) is true if M ∈ M(C) is a lower
Hessenberg matrix (H&J 0.9.9).
19. is_ upper_Hessenberg matrix(M) is true if M ∈ M(C) is an upper
Hessenberg matrix (H&J 0.9.9).
20. is _tridiagonal_ matrix(M) is true if M ∈ M(C) is a tridiagonal
matrix (H&J 0.9.10).
21. is _Jacobi _matrix(M) is true if M ∈ M(C) is a Jacobi matrix
(H&J 0.9.10).
22. is_ persymmetric_ matrix(M) is true if M ∈ M(C) is a
persymmetric matrix (H&J 0.9.10).
1. function is_real_matrix(M)
count=0;
for i=M
if(!isreal(i))
fprintf("\n The matrix has non real entries.")
count=count+1;
endif
endfor
if(!count)
fprintf("\n The matrix is real ! \n")
endif
endfunction
2. function is_complex_matrix(M)
count=0;
for i=M
if(iscomplex(i))
fprintf("\n The matrix has complex entries.")
count=count+1;
endif
endfor
if(!count)
fprintf("\n The matrix is not complex! \n")
endif
endfunction
3. function is_diagonal_matrix(M)
[c,d]=size(M)
if(c-d)
fprintf("\n The matrix is not square \n")
elseif (!(c-d))
if(isdiag(a))
fprintf("\n The matrix is diagonal!\n")
else
fprintf("\n It is not diagonal!\n")
endif
endif
endfunction
4. function is_lower_triangular_matrix(M)
[c,d]=size(M)
if(c-d)
fprintf("\n The matrix is not square \n")
elseif (!(c-d))
if(istril(a))
fprintf("\n The matrix is lower triangular!\n")
else
fprintf("\n It is not lower triangular!\n")
endif
endif
endfunction