Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use Rstudio to code 8 theorems Given a matrix M E Mmn, each function should firs

ID: 3756554 • Letter: U

Question

Use Rstudio to code 8 theorems Given a matrix M E Mmn, each function should first ensure that the matrix has the proper size (eg be square if the result being applied involves a square matrix). The following functions should be available: is.realmatrix(M) is true if MEM(R) ·is.complex.natrix(M) is true if M EM(C) and ,j such that g(mij)0. is.diagonal matrix(M) is true if M E M(C) is a diagonal matrix. is.lower triangular.matrix(M) is true if MEM(C) is a lower triangular matrix is.upper triangular matrix(M) is true if ME M(C) is an upper triangular matrix is.triangular matrix(M) is true if M EM(C) is a triangular matrix. is hermitian matrix(M) is true if ME M(C) is a Hermitian matrix is.skev hermitian matrix(M) is true if M E M(C) is a skew Hermitian matrix

Explanation / Answer

function matrix=matrix_functions
matrix.is_real_matrix=@is_real_matrix;
matrix.is_complex_matrix=@is_complex_matrix;
matrix.is_diagonal_matrix=@is_diagonal_matrix;
matrix.is_lower_triangle_matrix=@is_lower_triangle_matrix;
matrix.is_upper_triangle_matrix=@is_upper_triangle_matrix;
matrix.is_triangular_matrix=@is_triangular_matrix;
matrix.is_hermitian_matrix=@is_hermitian_matrix;
matrix.is_skew_hermitian_matrix=@is_skew_hermitian_matrix;
  
end

function a=is_real_matrix(M)
if isreal(M)
disp('Yes, matrix M is real')
else
disp('No, matrix M is not real')
end
end
function b=is_complex_matrix(M)
if isreal(M)
disp('No, matrix is not complex')
else
disp('Yes, matrix is complex')
end
end
function c=is_diagonal_matrix(M)
  
d=size(M);
rows=d(1);
cols=d(2);
found=0;
found1=0;
for i=1:rows
for j=1:cols
if (i~=j && M(i, j)~=0)
found=1;
break;
end
if (i==j && M(i, j)~=0)
found1=1;
end
end
end
if(found1==1 && found==0)
disp('Diagonal matrix')
else
disp('Not a diagonal matrix')
end
  
end
function d=is_lower_triangle_matrix(M)
d=size(M);
rows=d(1);
cols=d(2);
found=0;
for i=1:rows
for j=1:cols
if (i<j && M(i, j)~=0)
found=1;
break
end
end
end
if found==1
disp('Not an lower triangular triangle')
else
disp('Lower triangular matrix')
end
  
end
function f=is_upper_triangle_matrix(M)
d=size(M);
rows=d(1);
cols=d(2);
found=0;
for i=1:rows
for j=1:cols
if (i>j && M(i, j)~=0)
found=1;
break
end
end
end
if found==1
disp('Not an upper triangular triangle')
else
disp('Upper triangular matrix')
end
end
function g=is_triangular_matrix(M)
  
d=size(M);
rows=d(1);
cols=d(2);
  
found1=0;
for i=1:rows
for j=1:cols
if (i>j && M(i, j)~=0)
found1=1;
break
end
end
end
  
found2=0;
for i=1:rows
for j=1:cols
if (i<j && M(i, j)~=0)
found2=1;
break
end
end
end
if found1==1 || found2==1
disp('Triangular matrix')
else
disp('Not a triangular matrix')
end
end
function h=is_hermitian_matrix(M)
if M==transpose(conj(M))
disp('Hermitian Matrix')
else
disp('Not a hermitian matrix')
end
end
function s=is_skew_hermitian_matrix(M)
if M==-transpose(conj(M))
disp('Skew Hermitian Matrix')
else
disp('Not a Skew hermitian matrix')
end
end

On matlab terminal, just call,

x=function_name

x.is_hermitian_matrix(M) , to test if M is a hermitian matrix.