0% found this document useful (0 votes)
30 views

Matlab Arithmetic Operations

Arrays are rectangular patterns of numbers that are useful for storing multiple values with the same variable name. In Matlab, arrays with more than one dimension are called matrices. The most common arrays are 2D arrays (matrices) and 1D arrays (vectors). Matlab defines matrix operators for matrix operations that follow standard matrix rules, and array operators for element-by-element array operations. Vectors are 1D arrays that can be created between two numbers with fixed spacing or a fixed number of points.

Uploaded by

mrgaur gaur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Matlab Arithmetic Operations

Arrays are rectangular patterns of numbers that are useful for storing multiple values with the same variable name. In Matlab, arrays with more than one dimension are called matrices. The most common arrays are 2D arrays (matrices) and 1D arrays (vectors). Matlab defines matrix operators for matrix operations that follow standard matrix rules, and array operators for element-by-element array operations. Vectors are 1D arrays that can be created between two numbers with fixed spacing or a fixed number of points.

Uploaded by

mrgaur gaur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

 Any set of numbers arranged in the rectangular

pattern is called an Array

 Array is a very useful


concept to store more than 0 0 1 4 5
a data with same variable
name and used widely in
programming 0 0 2 3 4

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

 2-D array also called Matrix


 1-D array also called as vector (row/column)

“Biggest advantage of Matlab is the way it deals with


the 2-D array’s i.e. Matrices”
Arrays

Matrices

Vector

Scalars
In Matlab there are two classified arithmetic operations

 Matrix Operation
 Array Operation

 Matlab defines two different operators to perform


these operations which is unusual.
 Operators used to perform Matrix Operations are
called Matrix Operator
 Operators used to perform Array Operations are
called Array Operator
Matrix Operation (Follow rules of usual matrix
operation)

Arithmetic Operation Matix Operator

Addition A+B
Subtraction A-B
Multiplication A*B
Division A/B
Array Operation (Element-by-Element Operation)

Arithmetic Operation Array Operator

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

n Vector between two numbers can be


created in two ways one by changing
“h” and another by changing “n”
1. Fixed spacing (h)
h

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”

Last element stored in the vector not necessarily


same as “b”. It could be “b” or smaller than “b”
>> v=1:1:5
v=
1 2 3 4 5
>> v=1:3:5
v=
1 4
>> v=1:6 (default increment is 1)
v=
1 2 3 4 5 6

Generated vector is a row vector


2. Fixed no. of points (n)
h

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

Default value of n =100 taken by Matlab

You might also like