disp('Define a row vecor:') disp('x = [1 2 3 4 5]') x = [1 2 3 4 5] pause; disp('Define a sequence:') disp('x = [1:5]'); x = [1:5] pause; disp('Referencing vector contents:') disp('x(2)') x(2) pause disp('end is the last entry of the vector') disp('x(end)') x(end) pause disp('Taking a subvector (whose indices are defined by a vector)') disp('x(2:4)') x(2:4) pause disp('Taking the transpose of a vector') disp('x''') x' pause disp('Create a vector of all ones (create a vector of all 0 with zeros(...))') disp('x = ones(5,1)') x = ones(5,1) pause disp('Scalar-vector multiplication') disp('3*x') 3*x pause disp('Add the same scalar value to all the entries of a vector') disp('x+1') x+1 pause disp('Inner (scalar) product') disp('x''*x'); x'*x pause disp('Outer product (the result is a rank 1 matrix)') disp('x*x'''); x*x' pause; disp('Define a matrix') disp('A = [1 2 ; 3 4]') A = [1 2 ; 3 4] pause; disp('Take the transpose of a matrix') disp("A'") A' pause disp('Reference a matrix entry') disp('A(1,1)') A(1,1) pause; disp('The first index is the rows index, the second index is the columns index') disp('A(2,1)') A(2,1) pause; disp('Take a row of A') disp('A(1,:)') A(1,:) pause disp('Take a column of A') disp('A(:,2)') A(:,2) pause disp('Change the value of x') disp('x = ones(2,1)'); x = ones(2,1) pause disp('Matrix-vector (left) multiplication') disp('A*x') A*x pause disp('Matrix-vector right multiplication') disp('x''*A') x'*A pause disp('Define another matrix') disp('B = [5 6 ; 7 8]') B = [5 6 ; 7 8] pause; disp('Matrix addition') disp('A+B') A+B pause; disp('Matrix subtraction') disp('A-B') A-B pause disp('Matrix multiplication') disp('A*B') A*B pause; disp('Pointwise multiplication') disp('A.*B') A.*B pause; disp('Pointwise division') disp('A./B'); A./B pause disp('Solve a set of linear equations:') disp('x1+x2 = 2') disp('x1-x2 = 0') pause disp('Using Gauss-Jordan elimination:') disp('A = [1 1 ; 1 -1]; b = [2;0]; x = A\\b'); A = [1 1 ; 1 -1]; b = [2;0]; x = A\b pause; disp('or By taking the inverse of A:') disp('x = inv(A)*b') x = inv(A)*b pause; disp('create a 3x2 matrix') disp('A = [1 2 3; 4 5 6]''') A = [1 2 3; 4 5 6]' pause disp('Take a row of A') disp('A(2,:)') A(2,:) pause disp('Take a column of A') disp('A(:,1)') A(:,1) pause disp('Matrices are stored columnwise:') disp('A(:)') A(:) pause disp('Reshaping a matrix:') disp('reshape(A,2,3)') reshape(A,2,3) pause disp('Vectorized functions:') disp('t=-pi:0.1:pi;') t=-pi:0.1:pi; disp('y = sin(t);') y = sin(t); disp('Plot the graph') disp('plot(t,y)'); plot(t,y); pause