Professional Documents
Culture Documents
IT131-8L Machine Problem Answer Sheet
IT131-8L Machine Problem Answer Sheet
Machine
7 (Advanced Functions) Score
Problem #
Name Alonzo, Isaiah Benjamin B. Section A11
squarerootvalue =
posnum.m
Script:
function ans = posnum
%function posnum returns the output of the squareroot of the positive number
num = 0;
cnt = 0;
while num <= 0
num = input('Enter a positive number: ');
if num <= 0
%calls for a function named 'errcnt' that counts the number of errors
cnt = errcnt(cnt);
fprintf('Error #%0.0f: Follow instructions!\n',cnt);
%displays the number of errors in the program
fprintf('Does %0.0f look like a positive number to you?\n',num);
else
end
end
function cnt = errcnt(count)
cnt = count + 1;
a=
12
a=
12
v=
60
rectangular.m
Script:
function [a,v] = rectangular(l,w,h)
%this function takes the inputs from the user and solves for the area and
possibly the volume depending on the number of inputs
switch nargin
case 3
a = l*w;
v = l*w*h;
case 2
a = l*w;
otherwise
fprintf('Invalid Input\n');
end
ans =
3.5987e+06
stirling(1:2:10)
ans =
stirling definition
stirling = @(n)(sqrt(2*pi.*n).*((n/exp(1)).^n));