Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

G.V.P.

COLLEGE OF ENGINEERING
EXPT. NO. : DATE:

BASICS OF MATLAB

1) Allocate a value to a variable in mat lab


l=1 (like this we allocate)
Then the output will be
l=1
2) We can allocate an array of elements to a variable
l= [1 2 3]; (like this we allocate)
In this example we are ending the syntax with a semicolon (;). After entering the
variable which is assigned by a set of elements the output will be shown as
below
l (like this then press enter the below output will be coming)
l=
1 2 3

3) To get elements in a matrix order(m x n) the input should be given as


shown
l= [1 2 3 4 5; 1 2 3 4 5]
To visualise the output we need to enter the variable in which the elements
are stored. i.e.
l=
1 2 3 4 5
1 2 3 4 5

4) To get elements in a matrix order(m x n) the input should be given as


shown
i=l'
To visualise the output we need to enter the variable in which the elements
are stored. i.e.
i=
1 1
2 2
3 3
G.V.P. COLLEGE OF ENGINEERING
EXPT. NO. : DATE:

4 4
5 5

5) Multiplication of matrices
v=i*l;
v

v=

2 4 6 8 10
4 8 12 16 20
6 12 18 24 30
8 16 24 32 40
10 20 30 40 50

6) To get elements in a matrix order(m x n) the input should be given as


shown
l=
[1 2 3; 4 5 6; 7 8 9]
To visualise the output we need to enter the variable in which the elements
are stored. i.e.

l=

1 2 3
4 5 6
7 8 9

>> v= [9 8 7; 6 5 4; 3 2 1]

v=

9 8 7
6 5 4
G.V.P. COLLEGE OF ENGINEERING
EXPT. NO. : DATE:

3 2 1

Addition of two matrices


i=l + v

i=

10 10 10
10 10 10
10 10 10
7) Multiplication of two matrices
k=v. ^l
k=
9 64 343
1296 3125 4096
2187 256 1
8) Size of a matrix by using the command below
[m, n] =size (l)
m=
3
n=
3

9) To print required element by giving the address of the element as shown


below
l= [1 2; 3 4]\

l=
1 2
3 4
>> l (2, 2)
ans =
4
>> l (:,1)
ans =
G.V.P. COLLEGE OF ENGINEERING
EXPT. NO. : DATE:

1
3
>> l (1,:)
ans =
1 2
>> l (1:2,1)
ans =
1
3
>> l (1,1:2)
ans =
1 2

You might also like