Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE ONLY ATTEMPT IF YOU ARE SURE! I need the answer to number 8, but you can\

ID: 3755334 • Letter: P

Question

PLEASE ONLY ATTEMPT IF YOU ARE SURE!
I need the answer to number 8, but you can't do number 8 without number 7. so if you could do that as well, that would be great!


7. 70 Points Write a MATLAB function numcomp1() that reads two numbers numl and num2 from the keyboard, and then retruns 0 if numl and num2 are equal, returns 1 if numl is greater than num2, and returns -1 if numl is less than num2. 8. (30+40 70 Points) Rerite the MATLAB function numcomp1( developed in question 7 such that it takes two numbers numl and num2 as input arguments, and then retruns o if num1 and num2 are equal, returns 1 if numl is greater than num2, and returns -1 if num1 is less than num2 Rename the function as numcomp2. Test your code with the pairs (10, 5), (-3, -3), and (2, 10) as input. Attach a screen-shot.

Explanation / Answer

Answer 7
=========

Save the function in a file named numcomp1.m

function v = numcomp1()
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')
if num1 == num2
v = 0;
elseif num1 > num2
v = 1;
else
v = -1;
end


Now in command window you can call numcomp1() as
> numcomp1()


========================================================
Answer 8
========

Save the following code in numcomp2.m file

function v = numcomp2(num1, num2)
if num1 == num2
v = 0;
elseif num1 > num2
v = 1;
else
v = -1;
end

------
Now in command window, you can call the function numcomp2() as
> numcomp2(10, 5)
> numcomp2(-3, -3)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote