Sie sind auf Seite 1von 9

1 SUBJECT TITLE:

COMMUNICATION TO STUDY MATLAB COMMANDS 9


THEORY & TECHNIQUES

EXPERIMENT NO.1 DATE : ROLL NO. 43

To study
MATLAB
COMMANDS

Atmiya Institute of Technology & Science, Rajkot


2 SUBJECT TITLE:
COMMUNICATION TO STUDY MATLAB COMMANDS 9
THEORY & TECHNIQUES

EXPERIMENT NO.1 DATE : ROLL NO. 43

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

a=
1 2 3
4 5 6
7 8 9
This forms 3 X 3 matrix labeled as ‘a’

>> b=a’
b=
1 4 7
2 5 8
3 6 9
The transpose of matrix ‘a’ is stored in matrix ‘b’

>> c=b*a

c=
66 78 90
78 93 108
90 108 126
Multiplies matrix ‘b’ with ‘a’ stores in ‘c’

>> c = a*b
c=
14 32 50
32 77 122
50 122 194
Multiplies matrix ‘a’ with ‘b’ stores in ‘c’

>> a= [1 2 3 4 5]

a= 1 2 3 4 5
One dimensional array is defined as ‘a’

>> b = a+3
b=
4 5 6 7 8
‘3’ is added to each element of ‘a’

Atmiya Institute of Technology & Science, Rajkot


3 SUBJECT TITLE:
COMMUNICATION TO STUDY MATLAB COMMANDS 9
THEORY & TECHNIQUES

EXPERIMENT NO.1 DATE : ROLL NO. 43

>> c = a+b
c=
5 7 9 11 13
Both arrays ‘a’ and ‘b’ are added and stored in ’c’

>> eye(3)
ans =
1 0 0
0 1 0
0 0 1
identical matrix formed

>> eye(5)
ans =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
5 X 5 identical matrix formed

>> zeros(3,4)
ans =
0 0 0 0
0 0 0 0
0 0 0 0
3 x 4 matrix with all elements ‘0’

>> ones(3,4)
ans =
1 1 1 1
1 1 1 1
1 1 1 1
3 x 4 matrix with all elements ‘1’

Atmiya Institute of Technology & Science, Rajkot


4 SUBJECT TITLE:
COMMUNICATION TO STUDY MATLAB COMMANDS 9
THEORY & TECHNIQUES

EXPERIMENT NO.1 DATE : ROLL NO. 43

>>[eye(2);zeros(2)]
ans =
1 0
0 1
0 0
0 0
Identical matrix is appended with the 2 X 2 zero matrix

>> [eye(2),zeros(2)]
ans =
1 0 0 0
0 1 0 0
identical matrix is appended with the 2 X 2 zero matrix and 2 X 4 matrix is formed

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


a=
1 2 3
4 5 6
7 8 9
3 X 3 matrix is formed as ‘a’

>> a (2,1)
a =
4
This gives the value of 2nd row and 1st element

>> a(1,2)
a =
2
This gives the value of 1st row and 2nd element

>> c = [ a; 10 11 12]
c=
1 2 3
4 5 6
7 8 9
10 11 12
It appends a row in the matrix ‘a’

Atmiya Institute of Technology & Science, Rajkot


5 SUBJECT TITLE:
COMMUNICATION TO STUDY MATLAB COMMANDS 9
THEORY & TECHNIQUES

EXPERIMENT NO.1 DATE : ROLL NO. 43

>> [a; a; a]
ans =
1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9
this appends ‘a’ to itself one after another and forms 9X3 matrix

>> [ a,a; a,a]

ans =

1 2 3 1 2 3
4 5 6 4 5 6
7 8 9 7 8 9
1 2 3 1 2 3
4 5 6 4 5 6
7 8 9 7 8 9
This appends matrix ‘a’ on the both directions and forms 6 X 6 matrix

>> f = [ -0.5, 0.1, 0.5]


f=
-0.5000 0.1000 0.5000
It defines a row matrix with non integer elements

>> round(f)
ans =
-1 0 1
It assigns the nearest integer value

>> f = [ -0.4,0.1,0.5]
f=
-0.4000 0.1000 0.5000
It defines a row matrix with non integer elements

Atmiya Institute of Technology & Science, Rajkot


6 SUBJECT TITLE:
COMMUNICATION TO STUDY MATLAB COMMANDS 9
THEORY & TECHNIQUES

EXPERIMENT NO.1 DATE : ROLL NO. 43

>> round(f)
f=
0 0 1
It assigns the nearest integer value

>> ceil (f)


ans =
0 1 1
It assigns the highest integer value

>> sum(f)
ans =
0.2000
sum of all elements stored in matrix

>> fix(f)
ans =
0 0 0
The integer value is stored and the decimal value discarded

>> floor(f)
ans =
-1 0 0
It stores the lower nearest integer value

>> [ 1,2,3,4].*[1,2,3,4]
ans =
1 4 9 16
It directly multiplies each elements of 1st matrix with 2nd matrix

>> [1,2,3,4] + [ 1,2,3,4]


ans =
2 4 6 8
It directly adds each elements of 1st matrix with 2nd matrix

>> [1,2,3,4].^3
ans =
1 8 27 64
It makes cube of each elements of row matrix

Atmiya Institute of Technology & Science, Rajkot


7 SUBJECT TITLE:
COMMUNICATION TO STUDY MATLAB COMMANDS 9
THEORY & TECHNIQUES

EXPERIMENT NO.1 DATE : ROLL NO. 43

>> [1,2,3,4]*3
ans =
3 6 9 12
It multiplies each elements of row matrix with 3.

>>pi
ans =
3.1416
The value of π is displayed

>>eps
ans =
2.2204 e-016
The value of e is displayed

>>who
Your variables are:
a b e g
ans c f x
Displays all variables used

>> clear x
Your variables are:
a b e g
ans c f
clears the variable x

>> clear all


clears all the variables

>> x = -2: 1
x=
-2 -1 0 1
It forms series of integer from –2 to 1 with unit diff.

Atmiya Institute of Technology & Science, Rajkot


8 SUBJECT TITLE:
COMMUNICATION TO STUDY MATLAB COMMANDS 9
THEORY & TECHNIQUES

EXPERIMENT NO.1 DATE : ROLL NO. 43

>>length(x)
ans =
4
It gives the length of the series

>> t= 0:2:10
t=
0 2 4 6 8 10
It gives series from 0 to 10 with difference of 2.

>> a =magic(3)
a=
8 1 6
3 5 7
4 9 2
forms 3X3 matrix with each raw and column having same sum

>>a (2,:)
ans =
3 5 7
It displays 2nd raw with all elements

>> a(:,3)
ans =
6
7
2
It displays 2nd column with all elements

>>a(2:3:,:)
ans =
3 5 7
4 9 2
It displays 2nd to 3rd raw with all elements

Atmiya Institute of Technology & Science, Rajkot


9 SUBJECT TITLE:
COMMUNICATION TO STUDY MATLAB COMMANDS 9
THEORY & TECHNIQUES

EXPERIMENT NO.1 DATE : ROLL NO. 43

>> b = rand(5)
ans =
0.9501 0.7621 0.6154 0.4057 0.0579
0.2311 0.4565 0.7919 0.9355 0.3529
0.6068 0.0185 0.9218 0.9169 0.8132
0.4860 0.8214 0.7382 0.4103 0.0099
0.8913 0.4447 0.1763 0.8963 0.1389
generates a random 5X5 matrix

>> c = 100 * rand(3)


c=
20.2765 27.2188 74.6786
19.8722 19.8814 44.5096
60.3792 1.5274 93.1815
it multiplies each elements of random matrix with 100.

>> [eye(2);zeros(2);zeros(2)]
ans =
1 0
0 1
0 0
0 0
0 0
0 0

>> [eye(2);ones(2)]
ans =
1 0
0 1
1 1
2 1

>> [eye(2);ones(2);zeros(2)]
ans=
1 0
0 1
1 1
1 1
0 0
0 0

Atmiya Institute of Technology & Science, Rajkot

Das könnte Ihnen auch gefallen