MATH/CMSC 206 - Introduction to Matlab

Announcements Syllabus Tutorial Projects Submitting

Answers to Self-Test

1. The first would assign the 3x3 matrix as shown. The second would extract the third column from the matrix and return it as a row vector. Remember the : means everything in that position and the first position is the column. Thus we're taking all of columns which are 3 from the left. Here is the output:

A=[-2 3 0;1 -7 8; 0.1 2 2]
A(:,3)
A =

   -2.0000    3.0000         0
    1.0000   -7.0000    8.0000
    0.1000    2.0000    2.0000


ans =

     0
     8
     2

2. Remember the norm command is what we want! We'd do:

norm([1 2 -3 0 5])
ans =

    6.2450

3. If you haven't had linear algebra before you should know that the norm of a matrix is the square root of the sum of the squares of its entries. The sum of the square of its entries can also be gained by multiplying the matrix by its transpose. Thus we could do the following. We've included the norm command for comparison:

v=[2 -1 0 3]
sqrt(v*transpose(v))
norm(v)
v =

     2    -1     0     3


ans =

    3.7417


ans =

    3.7417