Beruflich Dokumente
Kultur Dokumente
A workshop by
Society of Chemical Engineers
Department of Chemical Engineering & Technology, IIT (BHU) Varanasi
MATLAB WINDOW
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
2
MATLAB WINDOW
Current Folder
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
3
MATLAB WINDOW
Command
Window
Current Folder
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
4
MATLAB WINDOW
Command
Window
Current Folder
Command History
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
5
MATLAB WINDOW
Workspace
Command
Window
Current Folder
Command History
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
6
STARTING OFF
M AT L A B i s a n i n t e r p r e t e r . i . e . I t r e a d s l i n e b y l i n e .
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
7
DEFINING MATRICES
M AT L A B ( M a t r i x L a b o r a t o r y ) s t o r e s a l l t h e v a r i a b l e s a s
matrices.
Yo u c a n a l s o u s e z e r o s ( ) o r o n e s ( ) o r e y e ( ) o r r a n d n ( ) .
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
8
A ( i , j) u s e d t o ac c e s s t h e j t h el em e nt of t h e i t h r ow.
T h e c o l o n o p e r a t o r, : i s u s e d t o s e l e c t m u l t i p l e e l e m e n t s a t a
time
e.g. A(1,:) selects all columns for the first row
A(2:3,1:5) selects first five columns of 2 nd & 3rd row
TASK 1
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
10
MATRIX OPERATIONS
Tr a n s p o s e : J u s t a d d a n a p o s t r o p h e a f t e r t h e m a t r i x n a m e .
e . g . Tr a n s p o s e o f A : A
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
11
TASK 2
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
12
MATRIX ALGEBRA
To m u l t i p l y / d i v i d e t h e c o r r e s p o n d i n g e l e m e n t s o f t h e m a t r i c e s ,
precede the operator by a dot.
e.g. A = B.*C
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
13
TASK 3
26
19
24
21
23
25
31
22
27
20
28
33
10
15
30
34
12
16
36
29
13
18
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
14
MATLAB SCRIPTS
M AT L A B e d i t o r c a n b e a c c e s s e d b y u s i n g t h e k e y w o r d e d i t .
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
15
THE .M FILES
If you want to run the script, type the name of the script in the
c o m m a n d w i n d o w a n d p r e s s e n t e r.
Caution: Before running the script, make sure that the current
folder holds the desired file to be executed.
Also, you need to save the file whenever a change is
made.
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
16
Conditional Statements
2.
If else end
switch case end
Looping Statements
for end
while end
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
17
CONDITIONAL STATEMENTS
If else end
Syntax:
if <condition>
Syntax:
Switch <x>
Statement 1;
Case a
statement 1;
else
Case b
statement 2;
Statement 2;
Case cstatement 3;
end
Otherwise
statement 4;
end
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
18
TASK 4
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
19
LOOPING IN MATLAB
T h e 2 b a s i c l o o p s i n M AT L A B a r e
For loop
While loop
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
20
LOOPING STATEMENTS
For end
Syntax:
WHILE END
Syntax:
while <condition>
Statement 1;
statement 1;
Statement 2;
statement 2;
end
end
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
21
TASK 5
A man is standing on the number 5 on the number line .
After every turn , the man doubles the integer he is on and
moves back 3 integers .
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
22
PLOTTING IN MATLAB
The first 2 parameters are the x and y matrices and the third
one is the line specification.
More than one line can be plotted by just adding on the variables
like before.
e . g . p l o t ( a , b , r. , c , d , b o , e , f , g - )
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
23
TASK 6
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
24
FUNCTIONS
Process them
Either display an output or return a set of output
variables.
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
25
FUNCTION SYNTAX
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
26
Use very high caution when dealing with the order of the
input and output arguments.
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
27
Determinant:
Length of 1D matrix:
length (A)
[ r, c ] = s i z e ( A )
diag (A)
sum (A,1) : Returns a row vector containing the sum of all the columns
of matrix A
sum (A,2) : Returns a column vector containing the sum of all the rows
of matrix A
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
28
Society of Chemical Engineers, Dept. of Chemical Engineering & Technology, IIT (BHU) Varanasi
29