This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: MATLAB Expressions • Matlab has an interactive mode – Many expressions are obvious (like addition, multiplication, etc.) – Some expressions (exponentials, natural logarithms, Bessel Functions, etc.) are not as obvious – The help , lookfor commands can be useful • Variables can be stored in Matlab – a = 5 – b = 2^3+6 – c = a+b • Some variables are built in. Be careful, you can change them – ans – pi – Inf – NaN Matrices and Vectors • Arrays are a collection of values referred to by a single variable name • Matrices can be defined several different ways 1. Manual Entry 1. Expressions that evaluate a matrix 1. Builtin functions that return matrices 1. Userwritten functions that return matrices 1. Importing matrix data from files on disk “Roger, Roger. What’s our vector, Victor?” Airplane • Vectors • Matrices Manual Entry >> A = [4 6 7; 5 3 2; 1 7 4] A = 4 6 7 5 3 2 1 7 4 >> u=[6 3 8] u = 6 3 8 >> v = [3.1; 4.2; 0.5; 9.0] v = 3.1000 4.2000 0.5000 9.0000 “The human mind has never invented a laborsaving machine equal to algebra.” Anonymous Expressions (e.g. Transpose) >> A = [4 6 7; 5 3 2; 1 7 4]; >> B=A' B = 4 5 1 6 3 7 7 2 4 Built in functions • diag, eye, ones, rand, length, linspace, logspace, zeros, size >> eye(4) % 4x4 Identity Matrix ans = 1 0 0 0 1 0 0 0 1 0 0 0 1 >> rand(3,4) % Matrix of random numbers between 0 and 1 ans = 0.8147 0.9134 0.2785 0.9649 0.9058 0.6324 0.5469 0.1576 0.1270 0.0975 0.9575 0.9706 More Built in Functions >> linspace(0,100,11) points ans = 0 10 20 30 40 50 60 70 80 90 100 >> x = logspace(1,5,3) x = 10 1000 100000 >> A = [1 3 5; 2 1 7; 4 3 2; 1 6 9]; 4 rows and 3 columns >> size(A) ans = 4 3 Subscript Notation >> A = [1 3 5; 2 1 7; 4 3 2; 1 6 9]; % A is 4x3 matrix >> A(2,3) % What is the value of A in the second row, 3 column? >> A(2,3)=6 % Change the value of A in the 2nd row and 3 column Colon Notation >> v = 1:10 % Create a vector starting at 1 and ending at 10 v = 1 2 3 4 5 6 7 8 9 10 >> u=1:2:10 % Create a vector starting at 1 going by twos u = 1 3 5 7 9 >> A = [1 3 5; 2 1 7; 4 3 2; 1 6 9]; % Create a 4x3 matrix >> A(:,2) % create a vector of the second column of A ans = 3 1 3 6 Math Matrix Operations • Addition and Subtraction (u+v, uv), Matrices must be same size “At the source of every error which is blamed on the computer you will find at least two human errors including the error of blaming it on the computer.” Anonymous • Review matrix multiplication • Dot Product >> A=ones(2,3); B=[1 2; 3 4; 5 6]; % Create Matrices >> A*B % Matrix Multiply ans = 9 12 9 12 >> u = [10 9 8 6]; v = [1;2;3;4]; % Create vectors >> u*v % Dot product really just matrix multiplication ans = 76 Vectorization and Array Operators • In Matlab, function is applied to all elements >> x = 0:pi/4:pi x = 0 0.7854 1.5708 2.3562 3.1416 >> y = cos(x) y = 1.0000 0.7071 0.0000 0.7071 1.0000 Vectorization and Array Operators >> A = [1 2 3; 4 5 6; 7 8 9]; >> B = [9 8 7; 6 5 4; 3 2 1]; >> A.*B >> A....
View
Full Document
 Spring '08
 Passovoy
 Management, Linear Algebra, matlab, Matrices, Ring

Click to edit the document details