HW 1: Julia


OR/ISE 501 - Fall 2021

Assigned: Tue, 24 Aug (Groups of 2)
Due: 11:59p, Tue, 31 Aug

Group Members:

Please use the Code cells in this Jupyter notebook to answer each of the following questions. Please run all of the cells in your notebook and then submit it via Moodle. (There is a Run All Cells command under the Run menu.)


(1) Given the array x = [3, 1, 2, 9, 5, 4], provide the single command (namely, one line of code with at most one assignment (i.e., equals sign =)) needed to perform the following actions. Unless noted, all of the actions should not modify x; instead, the result of the action will just be displayed in the notebook. If x is modified, then type x on a second line in the cell in order to display the result; the modified x should be used for subsequent actions.

(a) After first creating x, extract the third element from x

(b) Extract all but the last element from x

(c) Extract the first, third, first, sixth, and first element from x

(d) Reverse the elements of x

(e) Calculate the sum of all of the elements of x

(f) Calculate the sum from the first to the i th element of x, for all elements 1 to i in x

(g) Modify x by setting the second and sixth elements of x equal to zero; then type x on a second line in cell in order to display the result

(h) Using the result from (g), modify x by deleting its third element

(i) Using the result from (h), modify x by adding 7 to its end

(j) Using the result from (i), modify x by converting it into a 2 by 3 matrix, where the first row of the matrix has the first three elements of x


(2) Let x = [6, 2, 1, 4] and A = [2 7 9 7; 3 2 5 6; 8 2 1 5]. After first creating x and A (and then not subsequently modifying x or A), provide the single command needed to:

(a) Add x to each row of A

(b) Add x to the sum of each column of A (resulting in a 4-element array)

(c) Add twice the sum of x to each element of A

(d) Calculate the element-by-element product of each row of A and x

(e) For each row of A, calculate the sum of the element-by-element product of each row and x (resulting in a 3-element array)


(3) Given that x = [1, 5, 2, 7, 9, 0, 1] and y = [5, 1, 2, 8, 0, 0, 2], provide the single command needed to:

(a) Extract from x those values that are greater than the corresponding values of y

(b) Extract from x those values that are both greater than the corresponding values of y and less than 6

(c) Extract from x those values that are either less than 2 or greater than 6

(d) Modify y by adding 1 to each of its nonzero values

(e) Divide each element of y by the corresponding element of x as long as the element of x is nonzero (to avoid dividing by zero)

(f) Modify y by setting all of its zero values to 1


(4) Provide a single command needed to create or modify the following arrays:

(a) A two-row, three-column matrix consisting of all integer zero values

(b) A 3-by-4 matrix whose elements range from 1 to 12, increasing left to right and top to down:

(c) A 3-element array whose first element is the vector [1, 4, 2], second element is the matrix [2 5 4; 1 8 3], and third element is the scalar 6.5

(d) Multiply each element of the array from (c) by 2


(5) A chemical processing facility will operate 24 hours a day, seven days a week. As a byproduct of its operation, hazardous waste material is generated at a constant rate of 1 ton per day and will be stored until removal. The facility has contracted to have its hazardous waste removed three times per week. The truck that will be used has the capacity to remove up to 15 tons of material, but no other details regarding the contract are currently available. Estimate how many tons, on average, of the hazardous material will be in storage at the facility.


(6) Continuing with Ex 3 from Intro 3:

(a) Determine if it would be preferable to configure the machine with three fixtures for product 1, one fixture for product 2, and one fixture for product 3.

(b) Using the configuration from (a), estimate the probability that all of the fixtures will be occupied after the first ten orders are received.