Project

Week 2 - Coding basics

1. A=[1,2,3,4,5]

This means we are creating a matrix of size 1*5 i.e. a row vector and storing 1,2,3,4,5 values respectively in each cell.

Expected Output: A= 1 2 3 4 5

2. B=[1;2;3;4;5]

This means we are creating a matrix of size 5*1 i.e. a column vector and storing 1,2,3,4,5 values respectively in each cell.

Expected Output: B= 1

2

3

4

5

3. C = A*B'

This means we multiply A matrix with transpose of B matrix. This matrix multiplication is not valid as sizes of A and B matrices are 1*5 and 1*5 respectively so product is not possible. For product to be possible number of columns in A should be equal to number of rows in B.

So, out put will be error message saying "Inner matrix dimensions must agree"

4. C = B*A

This means we multiply B matrix with A matrix. This matrix multiplication is valid as sizes of B and A matrices are 5*1 and 1*5 respectively so product is possible. Resultant matrix will have 5*5 size.

Expected Output:

C=

1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25

5. A(1:end)

This will display all cell values of matrix A till the end or the last value in one row. Even if A were to be a 2*2 matrix, all values will be displayed in a single row using this in code.

Expected Output:

1 2 3 4 5

6. A(1:2)

This will display matrix A cell values having index from 1 to 2

Expected Output:

1 2

7. B(1:2,3)

This means in B matrix we are accessing 1st and 2nd row values in the third column. But B has only one column so we get an error saying "Index exceeds matrix dimensions."

8. B(length(B)-2)

We are accesing value of B at index=length(B)-2.length(B) gives the maximum dimension of B matrix which is 5. So index value is 5-2=3. So we will get value corresponding to 3rd index in matrix B.

Expected Output:

3

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.