This function returns a random scalar value between a lower and upper limit provided as inputs. It checks that there are only two double inputs, and generates an error otherwise. If the inputs are valid, it returns a randomly generated number between the lower and upper bounds.
This function returns a random scalar value between a lower and upper limit provided as inputs. It checks that there are only two double inputs, and generates an error otherwise. If the inputs are valid, it returns a randomly generated number between the lower and upper bounds.
This function returns a random scalar value between a lower and upper limit provided as inputs. It checks that there are only two double inputs, and generates an error otherwise. If the inputs are valid, it returns a randomly generated number between the lower and upper bounds.
function [random_value] = random_scalar(lower,upper)
% The function returns a random scalar value as a double, % where the first input argument "lower" is the lower limit, the second % input argument "upper" is the upper limit of the value to be % to be generated. % Function calling example: [random_value] = random_scalar(0.8,0.9) % answer : 0.877
% Error checking required input arguments
if nargin > 2 % if input arguments are more than 2 error("too many input arguments") elseif nargin < 2 % if input arguments are less than 2 error("less input arguments; require 2") elseif nargin == 2 % if input arguments are equal to 2 if isa(lower,"double") == isa(upper,"double") % if input arguments are doubles low_limit = lower; up_limit = upper; n = 1; random_value = low_limit + rand(1,n)*(up_limit - low_limit); else % if input arguments are not doubles error("Error : both input arguments must be doubles datatypes") end end
end
% CHRISTIAN EMMANUEL LUKWICHI -222441560- BEngTech (Metallurgical