given the matrix a = [ 1 -1 3; -1 2 5; 3 0 -4] and the vector b=[ 1; 0; -2], write a matlab scritp named problem1.m that computes the matrix b which is the transpose of a in matlab

main.m
a = [1 -1 3; -1 2 5; 3 0 -4]; % define matrix a
b = [1; 0; -2]; % define vector b
a_transpose = a'; % compute the transpose of matrix a
136 chars
4 lines

The ' symbol in MATLAB syntax is used to denote matrix transpose. Therefore, a' returns the transpose of a. To assign this transpose to a new matrix variable called a_transpose, we simply use the assignment operator =.

To verify that a_transpose is computed correctly, we can display it in the Command Window using the disp() function:

main.m
disp(a_transpose)
18 chars
2 lines

This will display the following output:

main.m
     1    -1     3
    -1     2     0
     3     5    -4
57 chars
4 lines

Finally, the problem statement states that we need to compute the matrix b, which is the transpose of a. Since we have already computed a_transpose, we can simply assign it to b using the assignment operator =:

main.m
b = a_transpose;
17 chars
2 lines

Now b contains the transpose of a, just as the problem statement asked. To verify this, we can again display b in the Command Window using the disp() function:

main.m
disp(b)
8 chars
2 lines

This will display the same output as a_transpose:

main.m
     1    -1     3
    -1     2     0
     3     5    -4
57 chars
4 lines

gistlibby LogSnag