Results 1 to 2 of 2

Math Help - Please help with MATLAB function

  1. #1
    Newbie
    Joined
    Apr 2010
    Posts
    14

    Smile Please help with MATLAB function

    (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
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    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)
    2)provide your attempt
    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
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. need a matlab function
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 1st 2011, 11:52 PM
  2. Matlab function
    Posted in the Math Software Forum
    Replies: 2
    Last Post: April 17th 2010, 09:11 PM
  3. is there any function in MATLAB?
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 4th 2010, 02:57 AM
  4. need help with matlab function
    Posted in the Math Software Forum
    Replies: 2
    Last Post: March 24th 2010, 10:47 AM
  5. Matlab while function
    Posted in the Math Software Forum
    Replies: 1
    Last Post: May 10th 2009, 12:46 AM

Search Tags


/mathhelpforum @mathhelpforum