%% Lab 2 – Your Name – MAT 275 Lab%% Example code% Example 1% NOTE: Delete examples before submission.A = [1 0; 0 -1]A = [1, 0; 0, -1]% NOTE: The two matrices above are the same. We can separate columns with% commas OR spaces, and separate rows with semi-colons.
%% Lab 2 – Your Name – MAT 275 Lab%% Example code% Example 1% NOTE: Delete examples before submission.A = [1 0; 0 -1]A = [1, 0; 0, -1]% NOTE: The two matrices above are the same. We can separate columns with% commas OR spaces, and separate rows with semi-colons.%%% The following code changes the element in the 1st row and 2nd column of% matrix A to 9. In general, we can extract or change elements in a matrix A% with the syntax A(row,column).A(1,2) = 9%%% We can create the original matrix A above one element at a time as% follows:% Initiate A as empty vector (optional but necessary in other cases).A = [];% Define matrix A one element at a time.A(1,1) = 1;A(1,2) = 0;A(2,1) = 0;A(2,2) = -1;% Display vector A.A%%% This example shows how we can extract elements, rows, or columns from a% matrix. A colon indicates “all elements.” So A(2,:) extracts elements in% all columns of A that are also in the 2nd row of A. Note: To run this% section, a matrix A must be saved in the workspace.disp(‘Extract second row’) % disp command displays a specified stringA(2,:)disp(‘Extract first column’)A(:,1)disp(‘Extract last element’)A(end,end)%%% Let’s declare a vector b and sove Ax = b where A is a known matrix, b is% a known vector, and x is an unkown vector with same dimensions as b. This% is the most fundamental problem in linear algebra.b = [1;2];x = A\b% solve Ax = b using backslash command% NOTE: These examples are not comprehensive. Make sure you also go through