Problem 1 as follows Custom Heaviside function The Heaviside
Problem 1 as follows (Custom Heaviside function) The Heaviside step function is defined H(z) = , x = 0 (a) (10 points) Create a user-defined Matlab function called \"H.m\" for the Heaviside step function. Your function definition should be siilar to that shown below: function y = H(x) % Input: % Output: “ -a one-dimensional array of real numbers y-an array the same size as x, giving H(a for each element of x NOTE: You may not call the built-in function heaviside\" in H.m
Solution
function y = H(x)
% Input:
% x - a one-dimentional array of real numbers
% Output:
% y - an array the same size as x, given H(x)
% for each element of x
n = size(x, 2);
y = zeros(1, n);
for i = 1:n
if (x(i) < 0)
y(i) = 0;
elseif (x(i) == 0)
y(i) = 1/2;
elseif (x(i) > 0)
y(i) = 1;
end
end
end