Matlab Arithmetic Operations
Matlab Arithmetic Operations
1 4 3 6 7
2 1 0 1 3
1 2 3 4 5
0 0 1 4 5 0 0 1 4 5
0 0 2 3 2
0 0 2 8 9
0 0 2 3 4 0 0 2 3 4
1 4 3 6 1
1 4 3 7 6
1 4 3 6 7 1 4 3 6 7
2-D array 3-D array
Higher-dimensional arrays are not so common
Very frequently used arrays are
Matrices
Vector
Scalars
In Matlab there are two classified arithmetic operations
Matrix Operation
Array Operation
Addition A+B
Subtraction A-B
Multiplication A*B
Division A/B
Array Operation (Element-by-Element Operation)
Addition A+B
Subtraction A-B
Multiplication A.*B
Right Division A./B
Left Division A.\B
Power A.^n
Array Operation (Element-by-Element Operation)
Multiplication
A.*B = aij*bij
>> A=[ 1 2;
3 4];
>> B =[5 6;
7 8 ];
>> C=A.*B
[1*5=5 2*6= 12;
3*7=21 4*8= 32]
Array Operation (Element-by-Element Operation)
Right Division
A./B = aij/bij
>> A=[ 1 2;
3 4];
>> B =[2 4;
6 8 ];
>> C=A./B
[1/2=0.5 2/4=0.5;
3/6=0.5 4/8=0.5]
Array Operation (Element-by-Element Operation)
Left Division
A.\B = bij/aij
>> A=[ 1 2;
3 4];
>> B =[2 4;
6 8];
>> C=A./B
[2/1=2 4/2= 2;
6/3=2 8/4= 2]
Array Operation (Element-by-Element Operation)
Power
A.^n = aij^n
>> A=[ 1 2;
2 4];
>> A.^2 =[1^2=1 2^2=4;
2^2=4 4^2=16 ];
Vectors: 1-D array is called vector.
a= starting point
b = end point
n = no. of data
h = step size ( interval)
a b
Syntax a b
>> v=a:h:b
a= starting point n
h= increment value
b= maximum possible value of the last element of
vector “v”
Syntax a b
>> v=linspace(a,b,n)
a= starting point n
b= last point
n= total no. of elements of vector
h=(b-a)/(n-1)
>> v=linspace(1,9,5) h=(9-1)/(5-1)=2
v=
1 3 5 7 9
>> v=linspace(1,5,4) h=(5-1)/(4-1)=1.3333
v=
1.0000 2.3333 3.6667 5.0000