Professional Documents
Culture Documents
Linear Control Systems EELE326 Introduction To Matlab
Linear Control Systems EELE326 Introduction To Matlab
EELE326
Lecture.1
Introduction to Matlab
part.1
Symbol operation
For example,
+ Addition
multiply two numbers
- Subtraction >> 3*5
* Multiplication divide two numbers
>> 15/3
/ Division elevate a number to some power:
^ Power >> 2^(-4)
2. Algebraical and logical operations
Example:
Evaluate F(x)=5x^5+23x-2/(5x) at x=4
>> (5*(4)^5)+(23*4)-(2/(5*4))
Exercise:
Compute the area of a circle of radius = 5
2. Algebraical and logical operations
Functions
𝒆 𝒙 : 𝐞𝐱𝐩 (𝒙)
√ 𝒙 :𝐬𝐪𝐫𝐭 (𝒙)
: pi
Example:
In the case that we can get an element from a matrix, for example the element in the second
row, third column of matrix A, we have to enter
>> A(2,3)
the result will be
ans =6
3. Basic syntax: vectors and matrices
When the algebraical operations are with vectors or matrices, the procedure is the
same, except that we have to take into account that inner matrix dimension must
agree. For example, multiply matrix A by B
( ) (
𝐴= ¿ 4∧¿ 3∧¿ 6 , 𝐵= ¿ 5∧¿ 8∧¿ 3
¿ 5∧¿ 7∧¿ 0 ¿ 1∧¿ 0∧¿ 6 )
entering in the Command Window A*B is a mistake, the
right way is enter
>> A*B’
ans =
20 24 18
5 0 0
3. Basic syntax: vectors and matrices
The inverse matrix can be calculated with the command inv. For example, the
inverse of matrix A
( )
¿ 1∧¿ 2∧¿ 0
𝐴= ¿ 1∧¿1∧¿ 5
¿ 1∧¿1∧¿ 3
4. Relational and Logical operations
if Condition 1
Statement 1
x=input('How old are you?');
elseif condition 2
if x<=5
Statement 2
disp('you are kid')
elseif condition 3
elseif x<=30
Statement 3
disp('you are young');
...
else
else
disp('age is just a number')
Statement n
end
end
6. Loop constructs: the for and while statements
When we want to repeat statements, we can use loops. They are constructed using
either the command for or the command while.
end
6. Loop constructs: the for and while statements
% disp(st);
s=s+st;
st=st+1;
end
sum=s
6. Introduction to Graphics: The Plot command
Now, we introduce a first notion to graphs, the command plot. It creates a graph in
which the elements of the vector/s or matrix used as input are plotted. This
command can plot the elements of one vector “a" versus other vector \b" or the
elements of a vector versus their index. For example
x = -3:0.1:7;
y = 2*x.^2 - 5*x -2;
plot(x,y)
Exercises:
1. Evaluate the following equations if s is given to be 5:
2 𝑠 2 +8 𝑠+6 30 (𝑠 +1)
A. 𝑇 (𝑠)= 3 2 𝑇 (𝑠)=
𝑠 + 8 𝑠 +16 𝑠 +6 B. (𝑠 +5)(𝑠+ 2)( 𝑠+3)
200
C. 𝑌 (𝑠)= 2
𝑠 +20 𝑠+ 200
H.W:
Y
Exercises:
2. Plot the following relation for the period between (-5 and 5) with step size of 0.1:
y = 5sin(20x);
H.W: Plot the following relation for the period between (-5 and 5) with step size of 0.1: