-
9
pages
-
English
-
Documents
Description
A Short Tutorial on Matlab( by T. Co, ©2003,2004 )Part I. BASICSI. Assigning Values to Variables, Vectors and Matrices• Use the equality symbol, e.g. A=3• Variables are case sensitive: temperature is not the same as Temperature• To check values, just type the variable name• There are special constants already available, e.g. pi, Inf• For complex numbers, either use 3+2i or 3+2j• Vectors and matrices are enclosed with square brackets:a) Elements of rows are separated by commas: A=[1,2,3]b) Elements of columns are separated by semicolons: B=[1;2;3]c) Matrices can be seen as columns of row vectors, C=[1,2,3;4,5,6]• Alternatively, use spaces to separate row elements and return keys for columnelements:B = [ 1 2 3 4 5 6 1 0 1]• To get size information,a) yields [# rows, # cols]size(A)b) size(A,1) yields # rowsc) size(A,2) yields # colsd) length(v) yields # elements in vector v• Some shortcuts are available:a) A = 1:0.1:2 yields a row vector [1, 1.1, 1.2, … , 1.9, 2]b) diag([1,2,3]) yields a diagonal matrix [1,0,0 ; 0,2,0 ; 0,0,3]c) diag([1,2,3],1) yields a matrix[ 0,1,0,0 ; 0,0,2,0 ; 0,0,0,3 ; 0,0,0,0 ]d) eye(4) yields an identity matrix of size 4x4e) yields a matrix of zeros of size 3x3zeros(3)f) zeros(size(A)) yields a matrix of zeroshaving the same size as Ag) ones(3), ones(2,5), ones(size(A))works the same as zeros() except it producesa matrix of onesh) rand(m,n) matrix of uniformly distributedrandom numbers of size m by ni) ...
-
Publié par
-
Langue
English