You are on page 1of 3

IT131-8L Machine Problem Answer Sheet

Machine
7 (Advanced Functions) Score
Problem #
Name Alonzo, Isaiah Benjamin B. Section A11

1. Command Window Results:


squarerootvalue = posnum
Enter a positive number: -5
Error #1: Follow instructions!
Does -5 look like a positive number to you?
Enter a positive number: -3
Error #2: Follow instructions!
Does -3 look like a positive number to you?
Enter a positive number: -1
Error #3: Follow instructions!
Does -1 look like a positive number to you?
Enter a positive number: 0
Error #4: Follow instructions!
Does 0 look like a positive number to you?
Enter a positive number: 9

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;

Prepared by: Geldof Resuello


Prepared date: March 2020
end
ans = sqrt(num);
end
%returns the output to the command window

2. Command Window Results:


a = rectangular(3,4)

a=

12

>> [a,v] = rectangular(3,4,5)

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

3. Command Window Results:


stirling(10)

ans =

3.5987e+06

stirling(1:2:10)

ans =

Prepared by: Geldof Resuello


Prepared date: March 2020
1.0e+05 *

0.0000 0.0001 0.0012 0.0498 3.5954

stirling definition
stirling = @(n)(sqrt(2*pi.*n).*((n/exp(1)).^n));

Prepared by: Geldof Resuello


Prepared date: March 2020

You might also like