HW 1: Julia¶
ISE 754, Fall 2024
Assigned: Wed, 21 Aug (Individual Assignment)
Due: 10:00a, Wed, 28 Aug
Please use the Code cells in this Jupyter notebook to answer 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., one 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, type x on a second line in the cell to display the modified x in full (otherwise, just the modified elements of x will be displayed; 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
(2) 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-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
(c) Multiply each element of the array from (c) by 2
(3) 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.
(4) Create a function d1 that determines the rectilinear distance between two points:
$ d = \lvert x_1 - x_2 \rvert + \lvert y_1 - y_2 \rvert $
(5) Create a function sum_d2 that returns the sum of the Euclidean distances between a single point and multiple other points.