Question
%Your first and last name: %Your 810/811 number: %Lab 06 %Your task for this lab assignment is to correctly implement %the functions called by typeofmatrix:
%Your first and last name:
%Your 810/811 number:
%Lab 06
%Your task for this lab assignment is to correctly implement
%the functions called by typeofmatrix:
% issquare, isdiagonal, isidentity,
% isuppertriangular, islowertriangular, and iszero
%based on their comments, provided code, and examples.
%The function typeofmatrix assumes arg1 is the name of the file
%in the current working directory that contains A's elements,
%where A is a matrix.
%The function typeofmatrix is already implemented for you to have
%consistent I/O with our examples. After you finish implementing
%the functions aforementioned, you should not change the source
%code in typeofmatrix.
function [] = typeofmatrix(arg1)
A = readmatrix(arg1);
display(A);
print("issquare(A)", issquare(A));
print("isdiagonal(A)", isdiagonal(A));
print("isidentity(A)", isidentity(A));
print("isuppertriangular(A)", isuppertriangular(A));
print("islowertriangular(A)", islowertriangular(A));
print("iszero(A)", iszero(A));
end
%Return true if A is a square matrix;
%otherwise return false.
%You may use Matlab's size function, but
%no other Matlab functions can be used to
%implement this function.
function [output] = issquare(A)
[m, n] = size(A);
if m == n
output = true;
else
output = false;
end
end
%Return true if A is a diagonal matrix;
%otherwise return false.
%You may use Matlab's size function and
%Matlab's matrix notation, but NO other built-in
%Matlab functions can be used to implement this function.
%You may call other functions you implement for
%this lab assignment.
function [output] = isdiagonal(A)
[m, n] = size(A);
output = true;
for i = 1:m
for j = 1:n
if i ~= j && A(i,j) ~= 0
output = false;
break;
end
end
if output == false
break;
end
end
end
%Return true if A is an identity matrix;
%otherwise return false.
%You may use Matlab's size function and
%Matlab's matrix notation, but NO other built-in
%Matlab functions can be used to implement this function.
%You may call other functions you implement for
%this lab assignment.
function [output] = isidentity(A)
[m, n] = size(A);
if m ~= n
output = false;
else
output = true;
for i = 1:m
for j = 1:n
if i == j && A(i,j) ~= 1
output = false;
break;
elseif i ~= j && A(i,j) ~= 0
output = false;
break;
end
end
if output == false
break;
end
end
end
end
%Return true if A is an upper triangular matrix;
%otherwise return false.
%You may use Matlab's size function and
%Matlab's matrix notation, but NO other built-in
%Matlab functions can be used to implement this function.
%You may call other functions you implement for
%this lab assignment.
function [output] = isuppertriangular(A)
[m, n] = size(A);
output = true;
for i = 1:m
for j = 1:n
if i > j && A(i,j) ~= 0
output = false;
return
end
end
end
end
%Return true if A is a lower triangular matrix;
%otherwise return false.
%You may use Matlab's size function and
%Matlab's matrix notation
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started