Exercises

Please complete each exercise or answer the question before reviewing the posted solution comments.

  1. Which of the following function names are not valid? and why?

    • new
    • HighestValue
    • 1stPoint
    • inside Polygon
    • costIn$
    • sales-cost
    • new - the word "new is a reserved word in many languages and is not at all descriptive, but it is a valid name in Matlab. Though, we really recommend against using "new" as the name of anything.
    • Highest_Value - is a valid name for a function or variable.
    • 1stPoint - is not a valid name in Matlab because names can not start with digits.
    • inside Polygon - is not a valid name in Matlab because names can not contain blank spaces.
    • costIn$ - is not a valid name in Matlab because names can not contain the $ character.
    • sales-cost - is not a valid name in Matlab because names can not contain the - character which is recognized as a minus sign indicating the subtraction operation.
  2. Which of the following function names are not valid? and why?

    • length
    • size
    • i
    • char
    • length - is a valid name for a function or variable but we advise that you not use it since it will override the pre-defined function named length.
    • size - is a valid name for a function or variable but we advise that you not use it since it will override the pre-defined function named size.
    • i - is a valid name for a function or variable but we advise that you not use it since it will override the pre-defined variable named i which stores the value of the imaginary number, the square root of -1.
    • char - is a valid name for a function or variable but we advise that you not use it since it will override the pre-defined variable named char which returns the ASCII value of a specified character.