You are on page 1of 12

_________________________________________________________________________

EXPERIMENT : 01
NO

TITLE : INTRODUCTION TO MATLAB AND


ITS BASIC CONCEPT

DATE OF : 11 – 09 - 2017
EXPERIMENT

REG NO : 150101009
BATCH : AERO 14-A

NAME : Abdul Haseeb Lodhi

CONTENTS

________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 1 of 12
_________________________________________________________________________

1. Purpose ........................................................................................................................ 3
2. Definition and Introduction ......................................................................................... 3
3. Basic Arithmetic Functions ......................................................................................... 4
4. Plotting and Furnishing Output Response ................................................................... 6

________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 2 of 12
_________________________________________________________________________

1. Purpose
Purpose of this experiment is to provide basic introduction to students. In this experiment,
there are explained some basic MATLAB programming syntax that plays important role
to pick basic concepts of control system.

2. Definition and Introduction


Definition
Matlab is an interactive software system for numerical computations and graphics. It is
used for the programming of complex engineering problems. In addition, it has a variety
of graphical capabilities and can be extended through programs written in its own
programming language. Many such programs come with the system and number of these
extend Matlab's capabilities to nonlinear problems such as the solution of initial value
problems for ordinary differential equations. While Matlab provide some important
toolbox.

Meaning of matlab
Matlab stands for matrix laboratory. As the name suggests, Matlab is especially designed
for matrix computations and solving systems of linear equations, scalar (single element), a
vector (one dimensional) or an nxm matrix (two dimensional) and multidimensional
matrix.

Matrix Laboratory
Matlab or Matrix Laboratory is a high-level language and interactive or environment that
enables you to perform computationally intensive tasks faster than with traditional
Programming languages such as C and FORTRAN. It integrates computation,
visualization, and programming in an easy to use environment where problems and
solutions are expressed in familiar mathematical notation to capture ideas that are created.

Main Uses
• High-level language for technical computing
• Development environment for managing code, files, and data
• Interactive tools for iterative exploration, design, and problem solving
• Mathematical functions for linear algebra, statistics, Fourier analysis, Filtering,
optimization, and numerical integration
• 2-D and 3-D graphics functions for visualizing data
• Tools for building custom graphical user interfaces
• Functions for integrating Matlab based algorithms with external Applications and
languages, such as C, C++, FORTRAN, Java, COM

________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 3 of 12
_________________________________________________________________________

3. Basic Arithmetic Functions


Arithmetic operations are consisted on Addition, Subtraction, Multiplication and Division
functions. While there are some other operations that are categorized as Colon operation,
Row vector, Column vector, Power factor, Arrays.

Arithmetic Operation
These operations are consisting on basic math formulas and by these, there can be verify
basic properties of relation such as associate property, communicative property.

>>a=4; b=7; c=-5;


>>a+b-c
ans =6

Colon Operation
This command can perform the step given in between two values.
Initial Value : Step Size : Final Value

>> 2:2:10
ans =2 4 6 8 10

If step size is not given, then it is understood as one.

>> 1:4
ans =1 2 3 4

If you did not want to include the initial value, then use the following formula as
Initial Value + Step Size : Step Size : Final Value

Power Factor

>> A=[2 4 6 8 10]


A = 2 4 6 8 10
>>B=A^2

Ooohh!! There is Error?


There is used scaler power factor and inputs must be a scalar and a square matrix.

>> B=A.^2
B = 4 16 36 64 100

Arrays

________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 4 of 12
_________________________________________________________________________

Arrays has its second name as Row vector in mathematic. It can be in Geometric form
random form. There are many logics to develop array that depend upon programmer such
as ‘FOR LOOP’ logic etc.

Geometric Array:
>> n=1:4
n =1 2 3 4

>> 3.^n
ans =3 9 27 81

Random Array:
>> x=[1 -1 5 10 11]
x = 1 -1 5 10 11

>> 2.^(1:2:7)
ans = 2 8 32 128

Matrix and operations

Basic operations that relates with matrices are transpose, inverse and determinant eigen
value etc. A matrix has mxn dimension.

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

A=
1 2 3
4 5 6
7 8 9

Determinant:
For determinant, ‘det(matrix variable)’ syntax is used such as

>> det(A)
ans = -9.5162e-16

Transpose:
You have also idea about transpose of matrix. In MATLAB, there are two syntax to
represents a matrix in transpose such as given below

________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 5 of 12
_________________________________________________________________________

>> b=A'

b=
1 4 7
2 5 8
3 6 9

>> transpose(A)
ans =
1 4 7
2 5 8
3 6 9

Inverse:
Inverse of any matrix through MATLAB can be calculated as

>> inv(A)
ans =1.0e+16 *

0.3153 -0.6305 0.3153


-0.6305 1.2610 -0.6305
0.3153 -0.6305 0.3153

4. Plotting and Furnishing Output Response


Propose of this section is that to familiar to examine behavior of different function how it
behaves by changing different conditions such as trigonometric, exponential, digital signal,
continues signal, step response and impulse response.

Plotting
Plotting is a procedure that show response of specific function or variable in picture form.
It has different form to exhibit response such as stairs, discrete and continues. There is
appear only one window for one response. If you want to check more than one response in
one window, then MATLAB provide facility to deal with this situation. There are some
syntax of plotting types as

‘plot(variable/function)’ it is for continues plotting


‘stem(variable/function)’ it is for discrete plotting
‘stairs(variable/function)’ it is for stair response.

For plotting more than one response in same window, there is given syntax as

‘subplot(m,n,p) or subplot(mnp)’
________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 6 of 12
_________________________________________________________________________

Where m and n represents number of rows and columns while p indicate number of entries
about responses.

MATLAB Code Output Response


n=-20:20;
x=cos(0.1*pi*n);

subplot(3,1,1);
plot(n,x)

subplot(3,1,2);
stem(n,x)

subplot(3,1,3);
stairs(n,x)

Furnishing

In this topic, there will be explained briefly about title axis titles that provide detail about
output response. Grid and labeling of title and x,y axis, have syntax that are given below
as
title(‘Output name’) it is used to give desired title to output response.
xlabel(‘name’) and ylabel(‘name’) this syntax is used to give name axis.
grid on/off it is used to scale output responded figure.

________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 7 of 12
_________________________________________________________________________

MATLAB Code Output Response


t=0:0.01:5;
a=1;
k=exp(a*t);
subplot(1,2,1)
plot(k)
grid on
title('Increasing
Exponential Function')
xlabel('Time')
ylabel('Amplitude')

h=exp(-1*a*t);
subplot(1,2,2)
plot(h)
grid on
title('Decreasing
Exponential Function')
xlabel('Time')
ylabel('Amplitude')

Legend and Desired Axis setting

Legend is used to display more than one responses to show difference between them. this
command automatically colored the responses. While MATLAB gives option to adjust his
own desired value of axis.

legend(string1,string2,string3, ...) it is syntax of legend

________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 8 of 12
_________________________________________________________________________

MATLAB Code Output Response


m=-1:1;
imp=[zeros(1,1) 1
zeros(1,1)];
stem(m,imp);
hold on

n=-5:5;
rmp=[zeros(1,5) 2
zeros(1,5)];
plot(n,rmp);
hold on

legend('Impulse
Response','Ramp
Response');
grid on
axis([-10 10 0 5]);
xlabel('time');
ylabel('amplitude');

Task

Q#1 Define Following metrics

0.45 0 9 0.9 11 60
𝑨=[ 0 −2 6 ] 𝑩=[ 5 −0.99 30]
0 4 0.03 78 − 88 0.89 90

a. Prove Commutative property of addition and multiplication


b. Find (𝑨𝑩)−𝟏 = 𝑩−𝟏 𝑨−𝟏
c. Find B is Symmetric or Skew Hermitian
d. If Ax=B is relation is given than find C matrix through matrix equation solving
method
Q#2 Plot trigonometric functions and its inverse through legend that have time period of
0 to 20 with sampling space of 0.1.

Q#3 Plot unit step signal and that overlap impulse function at same amplitude.

________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 9 of 12
_________________________________________________________________________

Ans 1:
A = [0.45 0 9; 0 -2 6; 0 4 0.03];
B = [0.9 11 60; 5 -0.99 30; 78-88 0.89 90];

Ans 1 (a):
if A + B == B + A
disp('Commutative Property For Addition Satisfies')
else
disp('Commutative Property For Addition Not Satisfies')
end

if A * B == B * A
disp('Commutative Property For Multiplication Satisfies')
else
disp('Commutative Property For Multiplication Not Satisfies')
end

Ans 1 (b):
if isequal(num2str(inv(A*B),'%12.5f'),num2str(inv(B)*inv(A),'%12.5f'))
disp ('Property For Inverse Satisfied ')
else
disp ('Property For Inverse Not Satisfied')
end

Ans 1 (c):

if isequal(num2str(transpose(B),'%12.5f'),num2str(B,'%12.5f'))
disp ('B is Symmetric ')
else
disp ('B is not Symmetric')
end

if isequal(num2str(-B,'%12.5f'),num2str(B','%12.5f'))
disp ('B is Skew Hermatian ')
else
disp ('B is not Skew Hermatian')
end

Ans 1 (d):

X = A\B;
disp(X)

Ans 2:

t = 0:0.1:20;
y = sin(t);
subplot(4,2,1)
________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 10 of 12
_________________________________________________________________________

plot(t,y);
grid on
title('Sine Function')
xlabel('Time')
ylabel('Amplitude')

syms t
subplot(4,2,2)
ezplot(csc(t),[0,20]);
grid on
title('Cosecant Function')
xlabel('Time')
ylabel('Amplitude')

t = 0:0.1:20;
y = cos(t);
subplot(4,2,3)
plot(t,y);
grid on
title('Cosine Function')
xlabel('Time')
ylabel('Amplitude')

syms t
subplot(4,2,4)
ezplot(sec(t),[0, 20]);
grid on
title('Secant Function')
xlabel('Time')
ylabel('Amplitude')

subplot(4,2,5)
ezplot(tan(t),[0,20]);
grid on
title('Tangent Function')
xlabel('Time')
ylabel('Amplitude')

subplot(4,2,6)
ezplot(cot(t),[0,20]);
grid on
title('Cotangent Function')
xlabel('Time')
ylabel('Amplitude')

Ans 3:
subplot(4,2,7)
m = -1:1;
imp = [0 1 0];
stem (m , imp);
hold on
m = -10:10;
step = [zeros(1,10) , ones(1,11)];
stairs(m, step);
grid on
title ('Overlap')
xlabel ('Time')
ylabel('Amplitude')

________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 11 of 12
_________________________________________________________________________

________________________________________________________________________
Experiment # 01 CONTROL SYSTEMS Page 12 of 12

You might also like