Anda di halaman 1dari 3

7205-2-1E AID: 1825 | 18/10/2013

a)

Consider the given array:


0.0 0.5 2.1 3.5 6.0
0.0 1.1 6.6 2.8 3.4
array1 (1)
2.1 0.1 0.3 0.4 1.3

1.1 5.1 0.0 1.1 2.0

The given array consists of 4 rows and 5 columns with the total elements of 4 5 20 .
The size of an array is represented as number of rows number of columns .

Write the MATLAB code to create the given array using Equation (1).

Type the following code in the MATLAB command window.

array1=[0.0 0.5 2.1 -3.5 6.0;0.0 -1.1 -6.6 2.8 3.4;2.1 0.1
0.3 -0.4 1.3;1.1 5.1 0.0 1.1 -2.0]

Press enter to execute the above code. The output is,

array1 =

0 0.5000 2.1000 -3.5000 6.0000


0 -1.1000 -6.6000 2.8000 3.4000
2.1000 0.1000 0.3000 -0.4000 1.3000
1.1000 5.1000 0 1.1000 -2.0000

Type the following given code in the MATLAB command window to find the size of
array1 .

size(array1)

Press enter to execute the above code. The output is,

ans =

4 5

Thus, the size of the given array is 4 5 .

b)

Write the MATLAB code to create the given array using Equation (1).

Type the following code in the MATLAB command window.

array1=[0.0 0.5 2.1 -3.5 6.0;0.0 -1.1 -6.6 2.8 3.4;2.1 0.1
0.3 -0.4 1.3;1.1 5.1 0.0 1.1 -2.0]

Press enter to execute the above code. The output is,

array1 =

0 0.5000 2.1000 -3.5000 6.0000


0 -1.1000 -6.6000 2.8000 3.4000
2.1000 0.1000 0.3000 -0.4000 1.3000
1.1000 5.1000 0 1.1000 -2.0000

The command array11,4 represents the value present at first row and fourth column
of array1.

Type the following given code in the MATLAB command window to find the value of
array11,4 .

array1(1,4)

Press enter to execute the above code. The output is,

ans =

-3.5000

Thus, the value of array11,4 is 3.5 .

c)

Write the MATLAB code to create the given array using Equation (1).

Type the following code in the MATLAB command window.

array1=[0.0 0.5 2.1 -3.5 6.0;0.0 -1.1 -6.6 2.8 3.4;2.1 0.1
0.3 -0.4 1.3;1.1 5.1 0.0 1.1 -2.0]
Press enter to execute the above code. The output is,

array1 =

0 0.5000 2.1000 -3.5000 6.0000


0 -1.1000 -6.6000 2.8000 3.4000
2.1000 0.1000 0.3000 -0.4000 1.3000
1.1000 5.1000 0 1.1000 -2.0000

The command array1:,1:2:5 represents an array consists of first, third and fifth
column of array1.

Type the following given code in the MATLAB command window to find the values of
array1:,1:2:5 .

array1(:,1:2:5)

Press enter to execute the above code. The output is,

ans =

0 2.1000 6.0000
0 -6.6000 3.4000
2.1000 0.3000 1.3000
1.1000 0 -2.0000

0 2.1 6
2 6.6 3.4
Thus, the value of array1:,1:2:5 is
2.1 0.3 1.3

1.1 0 2

Type the following given code in the MATLAB command window to find the size of
array1:,1:2:5 .

size(array1(:,1:2:5))

Press enter to execute the above code. The output is,

ans =

4 3

Thus, the size of array1:,1:2:5 is 4 3

d)

Write the MATLAB code to create the given array using Equation (1).

Type the following code in the MATLAB command window.

array1=[0.0 0.5 2.1 -3.5 6.0;0.0 -1.1 -6.6 2.8 3.4;2.1 0.1
0.3 -0.4 1.3;1.1 5.1 0.0 1.1 -2.0]

Press enter to execute the above code. The output is,

array1 =

0 0.5000 2.1000 -3.5000 6.0000


0 -1.1000 -6.6000 2.8000 3.4000
2.1000 0.1000 0.3000 -0.4000 1.3000
1.1000 5.1000 0 1.1000 -2.0000

The command array113,end represents the elements of first and third rows of last
column of array1.

Type the following given code in the MATLAB command window to find the values of
array1 13,end .

array1([1 3],end)

Press enter to execute the above code. The output is,

ans =

6.0000
1.3000

6
Thus, the value of array113,end is
1.3

Type the following given code in the MATLAB command window to find the size of
array1 13,end .

size(array1([1 3],end))

Press enter to execute the above code. The output is,


ans =

2 1

Thus, the size of array113,end is 2 1

Anda mungkin juga menyukai