CSCI 1320 Computer Science I: Engineering Applications

Assignment 1

MATLAB Intro

1. (15 points) Create a table (in a word processor or spreadsheet, not in MATLAB)

showing the range for all of the integer types (both signed and unsigned), including

the formula for the range. Calculate the minimum and maximum values yourself,

and then use the intmin and intmax functions to verify your results.

2. (15 points) Use help elfun or experiment to answer the following questions.

Briefly explain what each of the 4 rounding functions does. You are welcome to use

the information provided by help.

1. Is fix(6.5) the same as floor(6.5)?

2. Is fix(3.3) the same as fix(-3.3)?

3. Is fix(4.2) the same as floor(4.2)?

4. Is fix(-5.3) the same as floor(-5.3)?

5. Is fix(-7.2) the same as ceil(-7.2)?

6. Is round(-2.4) the same as floor(-2.4)?

7. Is round(-8.4) the same as ceil(-8.4)?

3. (10 points) What would be the result of the following expressions? Feel free to use

Matlab to verify your answers.

>> 3\9

>> – 5 ^ 2

>> (-5) ^ 2

>> 10-6/2+3

>> 3 == 5 + 2

>> ‘b’ >= ‘c’ – 1

>> 7 == 6 + 1

>> (7 == 6) + 1

>> xor(5 < 6, 8 > 4)

>> xor(‘c’ == ‘d’ – 1, 2 > 4)

4. (15 points) Provide the MATLAB expression rand() and/or randi() functions to

generate a random:

A. real number in the range (0, 25)

B. real number in the range (20, 50)

C. integer in the inclusive range from 1 to 10

D. integer in the inclusive range from 0 to 10

E. integer in the inclusive range from 50 to 100

5. (10 points) Write the MATLAB expressions that will do the following:

A. Create two variables x and y that will store positive or negative integers.

B. Return true if the value of x is greater than five or if the value of y is less than

ten, but not if both of those are true.

6. (20 points) Using only the integers 2 and 3, write as many expressions as you can

that result in 9. Try to come up with at least 10 different expressions (Note: don’t

just change the order). Be creative! Make sure that you write them as MATLAB

expressions. Use operators and/or built-in functions.

Submitting the assignment:

For each problem solved, write the solution in a text document. Submit the solution as .pdf

file through Moodle as Assignment 1. Include at the top of your document your name,

student ID, assignment number, and instructor name.