BASIC CODINGS
OBJECTIVE:
Need to explain what each of the programming statements given below and also tell what is the expected output from these lines.
GIVEN CODE:
1. A=[1,2,3,4,5]
2. B=[1;2;3;4;5]
3. C = A*B'
4. C = B*A
5. A(1:end)
6. A(1:2)
7. B(1:2,3)
8. B(length(B)-2)
EXPLANATIONS AND OUTPUTS:
1. EXPLANATION
- A=[1,2,3,4,5] is an array whose size of an matrix is 1X5.
- It has one row and five columns.
- , it represents a new column.
OUTPUT
2. EXPLANATION
- B=[1;2;3;4;5] is an array whose size of an matrix is 5X1.
- It has five rows and one column.
- ; it represents a new row.
OUTPUT
3. EXPLANATION
- In matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the second matrix.
- C = A*B' for ths code the output is not possible,beacause the number of columns in the first matrix is not equal to the number of rows in the second matrix.
- * it represents matrix multiplication.
4. EXPLANATION
- C = B*A in this code the number of columns in the first matrix is equal to the number of rows in the second matrix. So the matrix multiplication is possible.
- In this code the size of the matrix A is 1X5 and the size of the matrix B is also 5X1.
OUTPUT
5. EXPLANATION
- A(1:end) it display all the value in the A,from starting value to the ending value
- end represents the ending value in the A.
- : represent upto.
OUTPUT
6. EXPLANATION
- A(1:2) it display starting value and second value only.
OUTPUT
7. EXPLANATION
- B(1:2,3) for this code the output is not possible, because the B doesn't have third column.
8. EXPLANATION
- B(length(B)-2) it reads the length of the B ie the number of elements present in the row or column and then the value is subtracted by 2.
- length it display the greater value either in a row or column.
OUTPUT