% Problem 1 of HW 19 The user should not be asking for input values of a and b in the body of the function. a and b will be assigned values when the function is called. % Problem 2 of HW 19 The clear statement at the top of the function body will wipe out the values of a and b that are passed to the function. % Problem 3 of HW 19 function [area] = triarea(b,h) % % [area] = triarea(b,h) % % Function to compute the area of a triangle given the base and height. area = b*h/2; % Problem 4 of HW 19 function [s,d,p,q] = basicops(a,b) % % [s,d,p,q] = basicops(a,b) % % Funtion to perform some basic operations on a and b % s = a + b % d = a - b % p = a * b % q = a / b s = a + b; d = a - b; p = a * b; q = a / b; % Problem 5 of HW 19 function [nf] = myfact(n) % % [nf] = myfact(n) % % Function to compute n! nf = 1; for i = 1:n nf = nf * i; end Version with error checking to make sure n is a scalar integer that is >= 0 function [nf] = myfact(n) % % [nf] = myfact(n) % % Function to compute n! % This first statement is necessary to ensure that nf has some value when % the function terminates nf = NaN; if(~isnumeric(n)) disp('n must be a number') elseif(~isscalar(n)) disp('n must be a scalar') elseif(n ~= floor(n)) disp('n must be an integer') elseif(n < 0) disp('n must be an integer >= 0') else nf = 1; for i = 1:n nf = nf * i; end end