• Apr 16th 2010, 01:59 AM
shiiganB
(a) Write a function using "if‟ statements that takes two numbers as input and returns true or false for the conditions below (use 1 for true, 0 for false):

Conditions
1) Whether BOTH numbers are equal when rounded
2) Whether BOTH numbers are odd when rounded
3) Whether EITHER number is negative
4) Whether EITHER number is within 0.2 of +1
5) None of the above

The first line of the function code should be:
function [are_equal, are_odd, is_neg, is_near1, none] = MyCompare(n1,n2)

(b) Rewrite the function in part (a) WITHOUT using any „if‟ statements that takes two numbers as input and returns true or false given the conditions below (use 1 for true, 0 for false):

The first line of the function code should be:
function [are_equal, are_odd, is_neg, is_near1, none] = MyCompare2(n1,n2)

(c) Write an M-file to that uses the functions in part (a) and (b) to test the
following user inputs:
(i) -4 & -4
(ii) -4 & 4
(iii) 4 & 16
(iv) 3 & 3
(v) 0.8 & 1.2
• Apr 16th 2010, 05:21 AM
elbarto
4 posts that seem like you have only taken the time to copy and paste your homework questions isn't going to help you learn the material and I can tell you that there aren't many people on here willing to do it all for you.

To get the most out of this forum, take the time to

1)outline the question (yes you have done that)
3)state where you think the problem is or what you don't understand in the code.

until then the best advice I can give you is:

Code:

```EDU>> help if  IF Conditionally execute statements.     The general form of the IF statement is         IF expression         statements       ELSEIF expression         statements       ELSE         statements       END       The statements are executed if the real part of the expression     has all non-zero elements. The ELSE and ELSEIF parts are optional.     Zero or more ELSEIF parts can be used as well as nested IF's.     The expression is usually of the form expr rop expr where     rop is ==, <, >, <=, >=, or ~=.       Example       if I == J         A(I,J) = 2;       elseif abs(I-J) == 1         A(I,J) = -1;       else         A(I,J) = 0;       end       See also relop, else, elseif, end, for, while, switch.     Reference page in Help browser       doc if EDU>>```
Regards Elbarto