Presentation is loading. Please wait.

Presentation is loading. Please wait.

A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB.

Similar presentations


Presentation on theme: "A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB."— Presentation transcript:

1 A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB

2 Complement on Matrix manipulation 1 Relational operations Example >> A=rand(4,3) >> B=(A>.2)&(A<0.8) >> C=A.*B >> D=(A~=A(1,1)) 2 Logical operations

3 I NTRODUCTION TO M ATLAB 3 Operator Precedence You can build expressions that use any combination of arithmetic, relational, and logical operators. Precedence levels determine the order in which MATLAB evaluates an expression. Within each precedence level, operators have equal precedence and are evaluated from left to right. The precedence rules for MATLAB operators are shown in this list, ordered from highest precedence level to lowest precedence level: 1. Parentheses () 2. Transpose (.'), power (.^), complex conjugate transpose ('), matrix power (^) 3. Unary plus (+), unary minus (-), logical negation (~) 4. Multiplication (.*), right division (./), left division(.\), matrix multiplication (*), matrix right division (/), matrix left division (\) 5. Addition (+), subtraction (-) 6. Colon operator (:) 7. Less than ( ), greater than or equal to (>=), equal to (==), not equal to (~=) 8. Element-wise AND (&) 9. Element-wise OR (|)

4 I NTRODUCTION TO M ATLAB >> a|b&c is similar to >> a|(b&c) >> A = [3 9 5]; >> B = [2 1 5]; >> C = A./B.^2 C = 0.2000 9.0000 0.7500 >> C = (A./B).^2 C = 1.0000 81.0000 2.2500 Built-in functions and(A,B) equivalent to A & B or(A,B) equivalent to A | B not(A) equivalent to ~A Returns 1 for a vector where all elements of the vector are true (nonzero), and 0 if all elements are not true all Returns 1 for a vector where any element of the vector is true (nonzero), and 0 if no elements are true. any Find indices and values of nonzero elementsfind Sort array elements in ascending or descending ordersort Note: The all and any functions ignore any NaN values in the input arrays

5 I NTRODUCTION TO M ATLAB >> X = [1 0 4 -3 0 0 0 8 6]; >> indices = find(X) >> find(X > 2) >> find(X == 0) >> X = [1 0 4 -3 0 0 0 8 6]; >> indices = find(X) >> find(X > 2) >> find(X == 0) Returns the mean values of the elements along different dimensions of an array mean Returns the largest (smallest) element along different dimensions of an array max, min Return the sum of the elements along different dimensions of an array sum Calculates differences between adjacent elements of a vector diff Returns the products of the elements prod Returns the cumulative sum along different dimensions of an array. cumsum Returns the cumulative product along different dimensions of an array. cumprod 4 Some functions

6 I NTRODUCTION TO M ATLAB Examples >> a=rand(1,5) >> max(a) >> A=rand(3,6) >> max(A) >> max(max(A)) >> sort(a) >> sort(A) >> mean(a) >> mean(A) >> max(A) >> max(max(A)) >> a=rand(1,5) >> max(a) >> A=rand(3,6) >> max(A) >> max(max(A)) >> sort(a) >> sort(A) >> mean(a) >> mean(A) >> max(A) >> max(max(A))

7 I NTRODUCTION TO M ATLAB b returns the scalar product of the vectors a anddot(a,b) returns the cross product of the vectors a and b.cross(a,b) >> a = [1 2 3]; b = [4 5 6]; >> c = cross(a,b) >> d = dot(a,b) 5. Format function The format Function : controls the numeric format of the values displayed by MATLAB. The function affects only how numbers are displayed, not how MATLAB computes or saves them. >> x = [4/3 1.2345e-6] format short 1.3333 0.0000 format short e 1.3333e+000 1.2345e-006 format short g 1.3333 1.2345e-006 format long 1.33333333333333 0.00000123450000 format long e 1.333333333333333e+000 1.234500000000000e-00 format long g 1.33333333333333 1.2345e-006 format bank 1.33 0.00 format rat 4/3 1/810045 Special Characters % : Insert comment line into code >> x=[1:5] %create an row vector from 1 to 5 increment 1


Download ppt "A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB."

Similar presentations


Ads by Google