MATLAB Tutoriala whirlwind tourHinke Osingah.m.osinga@bris.ac.ukEngineering MathematicsQueen’s Building 2.12MATLAB Tutorial – p.1/30The BasicsMATLAB can do everything a calculator does>>(1+4)*3ans =15As is standard:+ and- are addition,/ is division and* is multiplication,ˆ is an exponentMATLAB Tutorial – p.2/30Everything is a Matrix!In MATLAB, a scalar is actually a 1×1 matrixa vector is an n×1 or 1× n matrix>>a = 3a =3a is the number 3, but also the 1×1 matrix [3]Here is how to create a row vector>>v = [1 2 3]v =1 2 3MATLAB Tutorial – p.3/30Everything is a Matrix!A semicolon tells MATLAB to start a new row, so>>w = [4; 5; 6]w =456is a column vector.With a’ you turn a column vector into a row vector>>w’ans =4 5 6MATLAB Tutorial – p.4/30Multiplication of matricesYou can multiply the vectorsv andw>>v*wans =32Recall: 1×3 times 3×1 gives 1×1Similarly, 3×1 times 1×3 gives 3×3>>A = w*vA =4 8 125 10 156 12 18MATLAB Tutorial – p.5/30Matrix operationsStandard multiplication is really matrix multiplicationDimensions must match!Try typing>>v*vHowever, MATLAB can do 1×1 times a matrix:>>3*ACheck what MATLAB does when adding a scalar anda matrix>>A + 2MATLAB Tutorial – p.6/30Elementwise operationsElementwise operations are done using a. before theoperator. For example, each element is squared using>>sqv = v.ˆ2sqv =1 4 9If two vectors (or matrices) have the same dimensionsyou can perform an elementwise ...
Voir