Exercise 1

1 Array Indexing

In the class ArrayIndexing below you should first define a 2x3-array and set values to every position in the array. Also define a second array while you're at it, with the same size but with different values. The last thing you should do is to change a few values in each array. Then you're done!

Oh, one more thing, what are the results after changing the values?



1.1 Tip

When you set the values in the arrays you can use the fill function to fill a whole array with a value. fill(value, nrOfRows, nrOfColumns).


1.2


1.2.1 array1

the result of array2 {{10, 1, 1}, {23, 1, 1}}


1.2.2 array2

the result of array2 {{1, 1, 1}, {100, 100, 100}}


1.2.3 Simulation of ArrayIndexing


2 Indexing with Scalar Expressions

In the class ArrayIndexing2 below you should first define a 2x2-array and set values to every position in the array. Then define a second 2x4-array with different values. This time you should change a whole row in each array.

What are the results after changing the values?



2.1


2.1.1 Simulation of ArrayIndexing2


2.1.2 array1

the result of array1 is {{9, 9}, {2, 20}}


2.1.3 array2

the result of array2 {{7, 7, 7, 7}, {6, 7, 8, 9}}


3 Accessing Array Slices with Index Vectors

What is the result of the vectors v1, v2, v3, v4, v5, v6, v7, v8 and v9 below?



3.1

3.1.1 v1

v1 gets the value {22, 33, 44}.


3.1.2 v2

v2 gets the third row of V, i.e. the vector {44, 11, 77}.


3.1.3 v3

v3 gets the second element (in brackets) in the third row in V, i.e. {11}.


3.1.4 v4

v4 gets the second row of W, i.e. {13, 88, 43}


3.1.5 v5

v5 gets the first and second elements of Y, i.e. {23, 24}


3.1.6 v6

v6 gets the first and second elements on the third row of W, i.e. {99, 43}


3.1.7 v7

v7 gets the first and second elements of the third row of V, i.e. {44, 11, 77}


3.1.8 v8

v8 gets the 3:rd through 4:th elements of Y as {25, 26}


3.1.9 v9

v9 gets the 1:st to 5:th elements step 2 elements as {23, 25, 27}


3.1.10 Simulation of Slice