Use R . .The result of this part of the assignment can consist of two parts: a n
ID: 3755127 • Letter: U
Question
Use R . .The result of this part of the assignment can consist of two parts: a non-mandatory companion PDF file with extended documentation of the functions produced, stating explicitly the definitions and theorems used, etc.; an R file (or multiple MatLab files) containing l the functions. The companion file is optional: if you comment your code abundantly, then it should not be required if no further mathematical developments are needed. . The functions must be named and take arguments as prescribed here, so that a single test function can be used to verify the results for all students Your companion file, if any, should be in PDF format Given a matrix ME Mm, each function should first ensure that the matrix has the proper size (e.g. be square if the reslt being applied involves a square matrix). The following functions should be available: is real matrix(M) is true if M E M(R) . is .complexnatrix(M) is true if M E M(C) and .j such that 3(rnij-0 is.diagonal matrix(M) is true if ME M(C) is a diagonal matrix · is-lower-triangular-matrix(M) s true if M E M1(C) is a lower triangular matrix is.upper triangular matrix(M) is true if M E M(C) is an upp triangular matrix. · is.triangular.matrix(M) is true if M E M(C) s a triangular matrix. . is .hermitían.natrix(M) is true if e M1(C) s a Hermitian matrix. . is. skew hermitian matrix(M) is true if M E·M(C) s a skew Hermitian matrixExplanation / 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.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.