chem 1b lec 10 Essay

Submitted By rong1994
Words: 2470
Pages: 10

% #########################################################################
% Lecture 10 script: Covers Chapter 7, Page 294 - 325
% ######################################################################### % ----------------- Summary --------------------------------------- % In this lecture we will revisit matrix algebra in MATLAB
% This includes:
% (1) Vector and matrix transpose
% (2) Vector addition and subtraction
% (3) Multiplication of vectors with scalars
% (4) Inner and outer products of vectors
% (5) Vectors norms
% (6) Orthogonal and orthonormal vectors
% (7) Matrix - vector multipication
% (8) Vector - matrix multiplication % The remaining part of this Chapter will be covered in the next lecture (10) % ----------------------------------------------------------------- % ----------------- Writing a MATLAB program ---------------------- % We first clear the memory clear % --------------------- VECTOR OPERATIONS ------------------------- % Imagine we have some vector "v" v = [0:1:5]; v = [1:5]; % And we like to make this a column (vertical vector). We can use the
% transpose sign w = v'; % Imagine that we have another vector "u" of same size as "v", u = [10:10:50]; % Now we can add and substract "u" and "w" r = u - v; % --> substraction % And addition y = u + v; % --> both these statements are only possible if both "u" and "v" are of same dimension
% With statements like this, MATLAB automatically takes element by element
% Thus a statement like "y = u + v" is similar to
% [u(1) + v(1) u(2) + v(2) u(3) + v(3) ..... u(end) + v(end)] % We can also multiply a vector with a scalar. No dot is needed, because
% the scalar is a single value! r = 5*u; % Same with division e = u/5; % It does not hurt to use the "." sign. The same result will occur e2 = u./5; % --> element by element like previous statement % ----------------------------------------------------------------- % ------------------ VECTOR INNER PRODUCT ------------------------- % The inner product, or dot product is an operation between two vectors of
% equal size (same number of elements). The inner product leads to a single
% number, for instance, x = [1:5]; y = [6:10];
% Now calculate inner product delta = x*y'
% INNER PRODUCT IS ALWAYS HORIZONTAL VECTOR TIMES VERTICAL VECTOR!!!!!!!!!
% AND RESULTS IN A SINGLE NUMBER
% NOTE THAT "x*y'" is exactly similar to "y*x'" delta2 = y*x'
% You see that "delta" and "delta2" are identical % A simple example of the use of an inner product. Imagine you have a
% company and you sell different product. A vector "q" quantifies how many
% products you have sold of each entity q = [2 2 3 2 1];
% And you also know the price of each entity p = [1.75 2.25 1.50 0.25 2.75];
% How much money did we make? q*p' % Again this is similar to p*q' % ----------------------------------------------------------------- % ------------------ VECTOR OUTER PRODUCT ------------------------- % Unlike the INNER product, the OUTER product results in a matrix. Whereas
% an INNER product is computed as a horizontal vector times a vertical
% vector, the outer product is the other way around. A vertical vector
% times a horizontal vector. OUTER vector products can only be calculated
% if both vectors have the same number of elements (like an INNER product)
% Thus if u and v are two row (horizontal vectors), then the OUTER product
% is defined as "u'*v" or "v'*u", for instance u = [1:5]; v = [60:10:100];
% Then the OUTER product is u'*v % With OUTER vectors the reverse statement is NO longer true v'*u % Gives a different answer. Simply write out the multiplication and you
% will see!!!!!!!!!!!! % ----------------------------------------------------------------- % -------------------------- VECTOR NORMS ------------------------- % A vector with five elements if five-dimensional. In many practical