Académique Documents
Professionnel Documents
Culture Documents
This book enables you to learn basic MATLAB which is mandatory before learning any toolbox of MATLAB.
This book contains complete notes on following topics:
MATLAB Arrays
Chapter on Arrays covers how to enter one-dimensional and two-dimensional array, mathematical operations
with array and built in functions for handling arrays.
MATLAB Functions
Chapter on functions covers in-built functions of MATLAB and how to solve linear equations in MATLAB. It also
covers how to create and use a function file.
Chapter on script file covers how to create a script file and commands used in script file.
MATLAB Loops
Chapter on loops clearly elucidates for-end and while-end loops. A student completely naïve to programming
can easily understand concept of loops which is helpful in learning any programming language. A complete
explanation on nested loop has been given along with programs which will help in developing algorithm making
skill.
Professionals use MATLAB across the world. We can draw two dimensional and three-dimensional plots with
just two or three lines of code. Scientists, Engineers and Economist widely use MATLAB software for drawing
two dimensional and three-dimensional graph. Our chapter on two dimensional and three-dimensional plots
teaches how to draw graph using inbuilt functions and how to format a plot using commands. This chapter
covers different commands used for three-dimensional plotting and how to observe extreme points using inbuilt
functions.
We can solve complicated questions of integral and differential calculus very easily using inbuilt functions. This
chapter teaches how to use inbuilt functions to solve complicated questions.
We can solve complicated differential equations up to nth order in Simulink very easily. Using function file, we
can solve first order differential equations very easily. This chapter covers how to solve linear first order
differential equation using function file.
In Conclusion, content of this book can be easily understood by the user. Programs are also given along with
theory to develop algorithm making skill. We have covered lucid and complete notes on basic MATLAB.
Complete notes on Simulink, Image processing, Simpower system toolbox and fuzzy logic toolbox will be
added very soon. Wherever and whenever you require any information about MATLAB you are just a click
away............
About us
Our mission is to be innovative and meticulous to create products that give students everywhere access to
enjoyable, free and effective study material. We prepare students for MS right from free GRE coaching on our
website www.onlinegrecoaching to improving SOPs. It is mandatory to learn MATLAB before going for MS.
Projects on MATLAB also helps in improving SOPs. Learn basic MATLAB from this app and wishing you a
successful MS program.
Content
Chapter 1………………………………………………………………………………………………………………………………4
Chapter 2……………………………………………………………………………………………………………………………. 2
Chapter 3………………………………………………………………………………………………………………………………54
Chapter 4………………………………………………………………………………………………………………………………78
Chapter 5………………………………………………………………………………………………………………………………99
Chapter 6………………………………………………………………………………………………………………………………126
Chapter 7………………………………………………………………………………………………………………………………151
Chapter 8………………………………………………………………………………………………………………………………178
Chapter 9………………………………………………………………………………………………………………………………209
Chapter 10………………………………………………………………………………………………………………………………233
Chapter-1
Interacting with MATLAB
MATLAB can be used as a programming language and as a simulation software developed by
mathworks. Our tutorial gives you aggressively a gentle introduction of MATLAB programming language
and simulink. It is assumed that the MATLAB software is installed on the computer and that the user can
start the program. Once the program starts, the window that opens contains three smaller windows
command window, workspace window and command history window. These are three of different
windows in MATLAB.
MATLAB WINDOWS
1 COMMAND WINDOW
2 EDITOR WINDOW
3 COMMAND HISTORY WINDOW
4 WORKSPACE WINDOW
5 CURRENT DIRECTORY WINDOW
COMMAND WINDOW – command window is MATLAB’s main window and opens when MATLAB is
started. It enters variables and runs programs.
EDITOR WINDOW-The Editor window is used for writing MATLAB programs. This window is opened
from the file menu in the command window. More details on editor window are given in chapter-3
where it is used to create a script file and in chapter-4 where it is used to create function file.
Fig 1.2 shows example of Editor window
WORKSPACE WINDOW-It provides information about the variables that are declared by user.
Current directory window or current folder- It shows list of files in current folder.
2 Subtraction - 5-3=2
3 Multiplication * 5*3 = 15
FUNCTION DESCRIPTION
sin(x) Sine of angle x(x in radians)
ROUNDING FUNCTIONS
FUNCTION DESCRIPTION
round(x) Round to the nearest integer
PREDEFINED VARIABLE
Pi – The number pi
eps – The smallest difference between two numbers equal to 2^(-52) = 2.2204e-16
whos – display a list of variables currently in their memory and their size
Chapter-2
CREATING ARRAYS AND MATHEMATICAL OPERATIONS WITH ARRAY
ROW VECTOR :- row vectors are created by enclosing the set of elements in square bracket
and putting space or comma between the elements.
For example :
>>r = [7 8 9 10 11];
COLUMN VECTOR :– These are created by enclosing the set of elements in square bracket
and putting semicolon between the elements.
For example :
>>r = [7;8;9;10;11]
ones(m,n)-It creates a matrix with m rows and n columns in which all elements are 1.
eye(n) -It creates a square matrix with n rows and n columns in which diagonal elements are 1 and non
diagonal elements are 0.
1
4
7
>> A = [5 9 2 4];
>> length(A)%built in function for finding length of array
ans =
2 size (A)
• Returns a row vector containing two elements one indicating number of rows and
another indicating number of column in matrix A.
ans =
3 3%it means that no. of rows = no. of column = 3
3 reshape(A,m,n)
• Rearrange a matrix A that has r rows and s columns to have m rows and n columns. r
times s must be equal to m times n.
B=
5 0
8 6
1 2
4 diag(A)
• when A is a vector or one dimensional array. Above function creates a square matrix
with the elements of A in the diagonal.
• When A is a matrix, above function creates a vector from diagonal elements of A.
>> A = [1 2 3];
>> B = diag(A)
B=
1 0 0
0 2 0
0 0 3
B=
1
5
9
ans =
2 3 4
6 8 10
13 9 11
>> A - B
ans =
0 1 2
2 2 2
1 7 7
MULTIPLICATION-
• Multiplication operation * is executed by MATLAB according to the rules of linear
algebra.
• If A and B are two matrices, the operation A*B can be carried out if the number of
column in matrix A is equal to number of rows in matrix B.
• Two vectors can multiply each other only if both have the same number of elements
and one is a row vector and other is column vector.
>> A = [1 2 3;4 5 6;7 8 9];
>> B = [1 2;3 4;5 6];
>> A*B %for multiplication number of columns in A should be equal to the number of rows in
B
ans =
22 28
49 64
76 100
>> c = [1 2 3];%multiplication of row vector with a column vector gives n*n matrix
>> d = [1;2;3];
>> c*d
ans =
14
>> e = [1;2;3];%multiplication of column vector with a row vector gives n*n matrix
>> f = [1 2 3];
>> e*f
ans =
1 2 3
2 4 6
3 6 9
IN- BUILT FUNCTIONS IN MATLAB
FUNCTION DESCRIPTION EXAMPLE
mean(A) • If A is a vector, returns >> A = [1 2 3;4 5 6;7 8 9];
the mean value of >> mean(A)
elements. ans =
• If A is a matrix, returns 4 5 6
the mean value of >> B = [5 9 2 4];
elements of particular >> mean(B)
column. ans =
5
max(A) • If A is a vector, returns >> A = [1 2 3;4 5 6;7 8 9];
largest element in A. >> max(A)
• If A is a matrix, returns a ans =
row vector containing 7 8 9
largest element of each >> B = [5 9 2 3 12];
column of A. >> max(B)
ans =
12
min(A) • If A is a vector, returns >> A = [1 2 3;4 5 6;7 8 9];
smallest element in A. >> min(A)
• If A is a matrix, returns ans =
row vector containing 1 2 3
smallest element of >> B = [5 9 2 3 12];
each column of A. >> min(B)
ans =
3
•
[d,n] = max(A) • If A is a vector, d is the >> A = [4 9 14 1 3];
largest element in A and >> [d,n] = max(A)
n is the position of d=
element(first if several 14
has same value) n=
• If A is a matrix, d is the 3
vector containing >> A = [1 2 3;4 5 6;7 8 9];
largest element of each >> [d,n] = max(A)
column of A and n is the
d=
row in which largest
7 8 9
element is present.
n=
3 3 3
sum(A) • If A is a vector, returns >> A = [1 2 3 4];
the sum of elements of >> b = sum(A)
vector. b=
• If A is a matrix, returns 10
the sum of elements of >> A = [1 2 3;4 5 6;7 8 9];
each column of A. >> b = sum(A)
b=
12 15 18
X = (A^-1)*B
or X = inv(A)*B
There are two methods for solving system of linear equations. First (left division method is
recommended, because in second method calculation of inverse may be less accurate, when large
matrices are involved)
x=
1.0000
1.0000
1.0000
.^ EXPONENTIATION
./ RIGHT DIVISION
.\ LEFT DIVISION
For example:-
https://www.amazon.in/MATLAB-TUTORIAL-Er-Sumit-Arya-
ebook/dp/B078MLYZND/ref=sr_1_fkmr0_1?ie=UTF8&qid=1514375261&sr=8-1-
fkmr0&keywords=matlab+tutorial+aumit+arya
https://www.amazon.com/dp/1976738474/ref=sr_1_2?ie=UTF8&qid=1514375505&sr=8
-2&keywords=matlab+tutorial+sumit+arya