%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MATLAB 341 worksheet %%% this file helps to get familiar with basic elements of MATLAB %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% M. Peszynska, 2008/10 %% Copyright Department of Mathematics, Oregon State University %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% INSTRUCTIONS: please type every line yourself %%% ignore all lines and text beginning with % %%% replace {yourname} etc. by yourname %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diary yourname %% elementary arithmetic operations, variables, and functions 3*pi+sqrt(4) t = pi/4 (cos(t))^2 + (sin(t))^2 %% input a column vector x = [1; 2; 3] %% input a row vector y = [1 2 3] %% change from a row vector to column vector x = y' %% operations on vectors: multiply a vector by a scalar pi * x y = y' %% (now y is a column vector) %% dot (inner) product of two column vectors x, y, x'*y %% compute outer product x * y' %% compute a vector as a component-by-component product of x and y x.*y %%%%%%%%%%% EXERCISE 1: %% set up a column vector 8x1 representing today's date, call it a %% set up a row vector 1x8 representing your birthday, call it b %% compute all possible products of a and b %%%%%%%%%% %% how to input a matrix A = [2 3 5; 7 11 13; 17 19, 23] %% how to access its elements A(1), A(3) %% the transpose of a matrix A' %% how to access the first column and rows from 1:2 A (1:2,1) %% how to access the first column and all rows A (1:3,1) A (:,1) %% how to get a matrix with random entries B = rand (3,5) %%%%%%%%%% EXERCISE 2: %%% Swap the first and last columns of B %%% Hint: you must save one of the columns in a vector %%%%%%%%%% EXERCISE 3: %%% Compute all possible products of A and B %%%%%%%%%% %% how to get the size of a vector/matrix if forgotten size(x) size(A) size(B) %% identity matrix I = eye(4) %% set up an elementary matrix of type I and verify its effect on A EI = [ 0 1 0; 1 0 0; 0 0 1] EI*A A*EI %%%%%%%%%% EXERCISE 4: %% 4a: Set up some elementary matrices of type I,II,III %% 4b: Test their action upon A %% 4c: Now show how to turn A into row echelon form using elementary matrices %%%%%%%%%% %% compute transpose of B B' %% compute determinant of A det(a) %% compute inverse of A inv(A) %% solve Ax = b b = [ 1 ; 2 ; 3] x = A \ b y = inv(A)*b %%%%%%%%%% EXERCISE 5: %% Set up matrix C equal to the one from 4x4 class example %% 5b: Compute its determinant and inverse (if possible) %% 5c: With the above (and if possible), compute its adjoint. %% 5d: Solve a linear system with Cy = b where b is the first column of identity matrix %% what should y be equal to (see step 5b) ? %%%%%%%%%%%%%%%%%%%%% %%%%%%%%%% EXERCISE 6 to be turned in: %% Set up matrix D of size 3x3 containing your OSU ID %% Do exercises 4c, 5b,c,d using D. %%%%%%%%%% %% Print your worksheet/diary, include comments using % %%%%%%%%%%