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

Write a function with the following header: function [positive, negative, zero,

ID: 3785701 • Letter: W

Question

Write a function with the following header: function [positive, negative, zero, special] = my_array_metrics_lgcl (array) where: array is an arbitrary n times m array of class double. positive is a scalar of class logical that is true if and only if array contains at least one strictly positive value. negative is a scalar of class logical that is true if and only if array contains at least one strictly negative value. zero is a scalar of class logical that is true if and only if array contains at least one zero value. special is a scalar of class logical that is true if and only if array contains at least one "special" value. Special values are NaN, Inf, and - Inf. Note that Inf is both positive and "special", and - Inf is both negative and "special". Test cases: >> [positive, negative, zero, special] = my_array_metrics_lgcl ([1theta]) positive = logical 1 negative = logical Theta zero = logical Theta special = logical

Explanation / Answer

% matlab code

function[positive, negative, zero, special] = my_array_metrics_lgcl(array)
positive = 0;
negative = 0;
zero = 1;
special = 1;
[n,m] = size(array);
for i=1:n
for j=1:m
if array(i,j) == Inf
positive = 1;
special = 1;
elseif array(i,j) == -Inf
negative = 1;
special = 1;
elseif array(i,j) == NaN
special = 1;
elseif array(i,j) < 0
negative = 1;
elseif array(i,j) > 0
positive = 1;
elseif array(i,j) == 0
zero = 1;
  
end
end
end
end

array = [5, 0 , 0, Inf, -1 , 7];
[positive, negative, zero, special] = my_array_metrics_lgcl(array);
disp("positive = logical ");
disp(positive);
disp("negative = logical");
disp(negative);
disp("zero = logical");
disp(zero);
disp("special = logical");
disp(special);

%{
output:

positive =
logical
1
negative =
logical
1
zero =
logical
1
special =
logical
1

%}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote