Presentation is loading. Please wait.

Presentation is loading. Please wait.

Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s.

Similar presentations


Presentation on theme: "Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s."— Presentation transcript:

1 Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s wife

2 What’s the output? >>A = [1 2 3; 3 5 6] >>B = [2 4 6; 6 10 18] >>C = B./A This statement stores the matrix: 1. C= 2. C= 3. C= 4. Can’t divide these matrices

3 What’s the output? >>A = [1 2 3; 3 5 6] >>B = [2 4 6; 6 10 18] >>C = B*A This statement stores the matrix: 1. C= 2. C= 3. C= 4.Can’t multiply these matrices: not the correct dimension – A is 2x3 B is 2x3

4 What’s the output? >>A = [1 2 3; 3 5 6] >>B = [1 1 1; 1 1 1] >>C = B*A’ This statement stores the matrix: 1. C= 2. C= 3. C= 4.Can’t multiply these matrices: not the correct dimension – A is 2x3 B is 2x3

5 What’s the output? >>A = [0:0.1:0.5] This statement stores the matrix: 1. A= 2. A= 3. A= 4.A =

6 NEXT TOPIC: MATLAB FUNCTIONS

7 MATLAB uses function names consistent with most major programming languages For example sqrt sin cos log

8 Function Input can be either scalars or matrices

9 Some functions return multiple results size function determines the number of rows and columns

10 You can assign names to the output

11 There are functions for almost anything you want to do Use the help feature to find out what they are and how to use them From the command window From the help selection on the menu bar

12 Elementary Math Functions abs(x)absolute value sign(x)plus or minus exp(x)e x log(x) natural log log10(x)log base 10

13 Rounding Functions round(x) fix(x) floor(x) ceil(x)

14 Trigonometric Functions sin(x)sine cos(x)cosine tan(x)tangent asin(x)inverse sine sinh(x)hyperbolic sine asinh(x)inverse hyperbolic sine sind(x)sine with degree input asind(x)inverse sin with degree output

15 Data Analysis max(x) min(x) mean(x) median(x) sum(x) prod(x) sort(x)

16 When x is a matrix, the max is found for each column

17 max valueelement number where the max value occurs Returns both the smallest value in a vector x and its location in vector x.

18 Vector of maximums Vector of row numbers Returns a row vector containing the minimum element from each column of a matrix x, and returns a row vector of the location of the minimum in each column of matrix x.

19 Determining Matrix Size size(x)number of rows and columns length(x)biggest dimension

20 Variance and Standard Deviation std(x) var(x)

21 Random Numbers rand(n) Returns an n by n matrix of random numbers between 0 and 1 rand(n,m) Returns an n by m matrix of random numbers These random numbers are evenly distributed

22 Gaussian Random Numbers randn(n) Returns an n by n matrix of Gaussian (i.e. normal) random numbers with a mean of zero and a variance of 1. randn(n,m) Returns an n by m matrix of Gaussian (i.e. normal) random numbers with a mean of 0 and variance of 1

23 Manipulating Matrices Defining matrices A matrix can be defined by typing in a list of numbers enclosed in square brackets. The numbers can be separated by spaces or commas. New rows are indicated with a semicolon. A = [ 3.5 ]; B = [1.5, 3.1]; or B =[1.5 3.1]; C = [-1, 0, 0; 1, 1, 0; 0, 0, 2];

24 Manipulating Matrices Defining matrices Define a matrix by using another matrix that has already been defined. Reference an element in a matrix Both row and column indices start from 1. B = [1.5, 3.1]; S = [3.0, B] S = [3.0, 1.5, 3.1]; T = [1 2 3; S] S = 3.0 1.5 3.1 T = 1 2 3 3.0 1.5 3.1 S(2) T(2, 2) T(4) The element value on row 2 and column 2 of matrix T Count down column 1, then down column 2, and finally down column 2 to the correct element of matrix T.

25 Manipulating Matrices Change values in a matrix S(2) = -1.0; changes the 2nd value in the matrix S from 1.5 to -1.0 Extend a matrix by defining new elements. S(4) = 5.5; Extend the matrix S to four elements instead of three. S(8) = 9.5; Matrix S will have eight values, and the values of S(5), S(6), S(7) will be set to 0. T(3, 3) = 10; T(4, 5) = 20;

26 Manipulating Matrices Using the colon operator Define an evenly spaced matrix H = 1:8 --- The default spacing is 1 time = 0.0:0.5:3.0 --- The middle value becomes the spacing. Extract data from matrices x = M( :, 1) --- extract column 1 from matrix M y = M( :, 4) --- extract column 4 from matrix M z = M(2, : ) --- extract row 2 from matrix M a = M(2:3, : ) --- extract rows 2 and 3 from matrix M b = M( :, 2:4) --- extract column 2 to column 4 from matrix M c = M(2:3, 3:5) --- extract not whole rows or whole columns from matrix M Converts a two dimensional matrix to a single column M( : ) M = 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7


Download ppt "Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s."

Similar presentations


Ads by Google