Wednesday 6 November 2013

MATLAB BASIC FUNDAMENTALS - PART2


Array Operations :

Samples :
Addition of two vectors 

A=[1 1 1] ; B=1:3

A+B

Ans = [2 3 4]

Scalar  and Matrix Multiplication :

A=[1 0 2 ; 3 1 4]

3.*A

ans = [
3 0 6 ; 9 3 12]

Matrix Operations :

Samples :

Product of two matrices :
A = [1 3 ; 2 4]

B = [3 0 ; 1 5]

A*B

Ans = [
6 15 ; 10 20]



Element-wise product of matrices :


A.*B

ans = [
3 0 ; 2 20]



For array multiplication 

Relational Operators :

Samples :

A = [2 7 6 ; 9 0 5 ; 3 0.5 6] ;
B = [8 7 0 ; 3 2 5 ; 4 -1 7] ;

A==B

Ans = [ 0 1 0 ; 0 0 1 ; 0 0 0]

Short-Circuit Operators :

Samples :



To avoid attempting divide by zero and  

x = (b ~= 0) && (a/b > 18.5)

Operator Precedence :

A=[ 3 9 5 ] ;

B=[ 2 1 5 ] ;

C = (A./B).^2

C= [ 2.2500  81.0000  1.0000 ]

MATLAB Special Values :

Samples :

x=2*pi
x =
6.2832


No comments:

Post a Comment