0% found this document useful (0 votes)
65 views50 pages

Control Systems Lab: Introduction To MATLAB

The document provides an introduction to MATLAB. It outlines the basic operations in MATLAB like defining arrays and matrices, performing basic operations on them, plotting graphs, and plotting equations. It also discusses plotting multiple graphs in separate figures. The overall document serves as a tutorial for beginners to learn the basics of MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views50 pages

Control Systems Lab: Introduction To MATLAB

The document provides an introduction to MATLAB. It outlines the basic operations in MATLAB like defining arrays and matrices, performing basic operations on them, plotting graphs, and plotting equations. It also discusses plotting multiple graphs in separate figures. The overall document serves as a tutorial for beginners to learn the basics of MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Control Systems Lab

Introduction to MATLAB

Surrayya Mobeen

Department of Aeronautics and Astronautics


Institute of Space Technology, Islamabad

S.M (IST) CSLab 1 / 32


Outline

1. Introduction

2. Basic Operations in MATLAB

3. Task

S.M (IST) CSLab 2 / 32


Learning Objectives

 MATLAB

S.M (IST) CSLab 3 / 32


Learning Objectives

 MATLAB

 Basic operations in MATLAB

S.M (IST) CSLab 3 / 32


Learning Objectives

 MATLAB

 Basic operations in MATLAB

 Lab Task

S.M (IST) CSLab 3 / 32


Outline

1. Introduction

2. Basic Operations in MATLAB

3. Task
ÿ + (1 + a)ẏ + ay = u, a = −0.01, 0, 0.01

S.M (IST) CSLab 4 / 32


Open loop Response

S.M (IST) CSLab 5 / 32


Unity Feedback Control

S.M (IST) CSLab 6 / 32


...
T y + (1 + 21T )ÿ + (21 + 20T )y + 20 = 400uT − 400u̇, T = 0, 0.015, 0.030

S.M (IST) CSLab 7 / 32


Open loop Response

S.M (IST) CSLab 8 / 32


Unity Feedback Control

S.M (IST) CSLab 9 / 32


Outline

1. Introduction

2. Basic Operations in MATLAB

3. Task
What is MATLAB?

 Cleve Moler, the chairman of the computer science department at the


University of New Mexico, started developing MATLAB in the late 1970s.

S.M (IST) CSLab 10 / 32


What is MATLAB?

 Cleve Moler, the chairman of the computer science department at the


University of New Mexico, started developing MATLAB in the late 1970s.

 Jack Little, an engineer, was exposed to it during a visit Moler made to


Stanford University in 1983.

S.M (IST) CSLab 10 / 32


What is MATLAB?

 Cleve Moler, the chairman of the computer science department at the


University of New Mexico, started developing MATLAB in the late 1970s.

 Jack Little, an engineer, was exposed to it during a visit Moler made to


Stanford University in 1983.

 It is now also used in education, in particular the teaching of linear algebra


and numerical analysis, and is popular amongst scientists involved in image
processing.

S.M (IST) CSLab 10 / 32


Arrays

 Consider an array `u' of numbers as given below

u = 0 1 2 3 4 5 6 7 8 9 10

S.M (IST) CSLab 11 / 32


Arrays

 Consider an array `u' of numbers as given below

u = 0 1 2 3 4 5 6 7 8 9 10

 There are various methods to dene this array in MATLAB.

S.M (IST) CSLab 11 / 32


Arrays

 In this method, all the numbers are separately written in MATLAB

S.M (IST) CSLab 12 / 32


Arrays

 In this method the command is written in such a manner that MATLAB


automatically denes the array with an interval of 1 between the 1st and the
last number.

S.M (IST) CSLab 13 / 32


Arrays

 In this method the user species the 1st and the last number of the array and
the interval between two consecutive numbers of the array

S.M (IST) CSLab 14 / 32


Matrix
 Let `A' and `B' be two matrices
   
1 5 10 2 3
A= 2 3 7  B= 5 4 
6 1 1 6 8

S.M (IST) CSLab 15 / 32


Matrix

 To compute the size of any matrix the command size is used. For example,
we want to nd the size of B matrix.

S.M (IST) CSLab 16 / 32


Matrix

 Two matrices can be easily multiplied in MATLAB. However, the number of


columns in the 1st matrix should be equal to the number of rows in the 2nd
matrix.

S.M (IST) CSLab 17 / 32


Matrix

 Any row or column or a single element of a matrix can be extracted using


MATLAB command. Suppose we want to extract the 1st and 2nd row of
matrix A.

S.M (IST) CSLab 18 / 32


Matrix

 Similarly, if you want to extract the 2nd element (column) in the 3st row of
matrix A.

S.M (IST) CSLab 19 / 32


Matrix

 Matrix equation can also be solved using MATLAB.

S.M (IST) CSLab 20 / 32


Matrix

 Matrix equation can also be solved using MATLAB.

 Suppose that we want to solve the system Ax = B . This can be written as:

x = A−1 B

S.M (IST) CSLab 20 / 32


Plotting Graphs

 Plotting a graph between two variables can be done in dierent ways


depending on how the variables are linked.
Angle of Attack (deg) Coecient of lift

0 0
5 0.5
10 1
15 1.5
17 1.6
18 1.55
19 1.5

S.M (IST) CSLab 21 / 32


Plotting Graphs

S.M (IST) CSLab 22 / 32


Plotting Graphs

 Let's consider a more complex case.


Angle of Attack (deg) Coecient of lift

0 0
4 0.5
8 1.1
12 1.55
16 1.6
17 1.55
18 1.5

S.M (IST) CSLab 23 / 32


Plotting Graphs

S.M (IST) CSLab 24 / 32


Plotting Graphs

S.M (IST) CSLab 25 / 32


Plotting Graphs

 If for instance, you have already plotted 1 curve on a gure and without
writing a new code you want to add a new curve to the same plot, then the
`hold on' command is used. The code for this case would be:

S.M (IST) CSLab 26 / 32


Plotting Graphs

 If you have plotted one graph and want to plot another graph in a separate
window, then by default if you just use the plot command, MATLAB would
overwrite the existing graph but this not what you want. So for this,gure()
is used.

S.M (IST) CSLab 27 / 32


Plotting Graphs

 If you have plotted one graph and want to plot another graph in a separate
window, then by default if you just use the plot command, MATLAB would
overwrite the existing graph but this not what you want. So for this,gure()
is used.

 This would open both curves in separate gures.

S.M (IST) CSLab 27 / 32


Plotting an Equation

 If the variables are linked through an equation and you are to plot a graph
between the two variables, then one variable is dened as an array and the
second variable is given as a function of the rst variable.

S.M (IST) CSLab 28 / 32


Plotting an Equation

 If the variables are linked through an equation and you are to plot a graph
between the two variables, then one variable is dened as an array and the
second variable is given as a function of the rst variable.

 As an example consider the variation of temperature within the troposphere.

S.M (IST) CSLab 28 / 32


Plotting an Equation

 If the variables are linked through an equation and you are to plot a graph
between the two variables, then one variable is dened as an array and the
second variable is given as a function of the rst variable.

 As an example consider the variation of temperature within the troposphere.


o
 We know that temperature decreases at a constant rate of6.5 C/1000m. So
the equation becomes
6.5h(m)
T = To −
1000

S.M (IST) CSLab 28 / 32


Plotting an Equation

 If the variables are linked through an equation and you are to plot a graph
between the two variables, then one variable is dened as an array and the
second variable is given as a function of the rst variable.

 As an example consider the variation of temperature within the troposphere.


o
 We know that temperature decreases at a constant rate of6.5 C/1000m. So
the equation becomes
6.5h(m)
T = To −
1000
 Where T0 is sea level temperature and 0 < h(m) < 11000m. If for instance
o
T0 = 15 C .

S.M (IST) CSLab 28 / 32


Plotting an Equation

 If the variables are linked through an equation and you are to plot a graph
between the two variables, then one variable is dened as an array and the
second variable is given as a function of the rst variable.

 As an example consider the variation of temperature within the troposphere.


o
 We know that temperature decreases at a constant rate of6.5 C/1000m. So
the equation becomes
6.5h(m)
T = To −
1000
 Where T0 is sea level temperature and 0 < h(m) < 11000m. If for instance
o
T0 = 15 C .
 The the equation would be:

6.5h(m)
T = 15 −
1000

S.M (IST) CSLab 28 / 32


Plotting an Equation

S.M (IST) CSLab 29 / 32


Plotting an Equation

S.M (IST) CSLab 30 / 32


Outline

1. Introduction

2. Basic Operations in MATLAB

3. Task
Task

1. Dene Following Matrices

 
1.2 3.04 7.3 3.2  
1.3 1.6
 −1 −12 1.2 5 
 −1
  4.5 
A= 2.7 1 −2 4  B=
 2.5

  5.9 
 6.6 4.51 0 1 
4.8 −6.3
−3 −2.2 1 6

S.M (IST) CSLab 31 / 32


Task

1. Dene Following Matrices

 
1.2 3.04 7.3 3.2  
1.3 1.6
 −1 −12 1.2 5 
 −1
  4.5 
A= 2.7 1 −2 4  B=
 2.5

  5.9 
 6.6 4.51 0 1 
4.8 −6.3
−3 −2.2 1 6

1.1 Compute is size of A

S.M (IST) CSLab 31 / 32


Task

1. Dene Following Matrices

 
1.2 3.04 7.3 3.2  
1.3 1.6
 −1 −12 1.2 5 
 −1
  4.5 
A= 2.7 1 −2 4  B=
 2.5

  5.9 
 6.6 4.51 0 1 
4.8 −6.3
−3 −2.2 1 6

1.1 Compute is size of A


1.2 Compute AB

S.M (IST) CSLab 31 / 32


Task

1. Dene Following Matrices

 
1.2 3.04 7.3 3.2  
1.3 1.6
 −1 −12 1.2 5 
 −1
  4.5 
A= 2.7 1 −2 4  B=
 2.5

  5.9 
 6.6 4.51 0 1 
4.8 −6.3
−3 −2.2 1 6

1.1 Compute is size of A


1.2 Compute AB
1.3 Extract the elements of A that are in 2nd to 4th row and 1st & 3rd Columns

S.M (IST) CSLab 31 / 32


Task

1. Dene Following Matrices

 
1.2 3.04 7.3 3.2  
1.3 1.6
 −1 −12 1.2 5 
 −1
  4.5 
A= 2.7 1 −2 4  B=
 2.5

  5.9 
 6.6 4.51 0 1 
4.8 −6.3
−3 −2.2 1 6

1.1 Compute is size of A


1.2 Compute AB
1.3 Extract the elements of A that are in 2nd to 4th row and 1st & 3rd Columns
1.4 Solve Ax = B for x.

S.M (IST) CSLab 31 / 32


Task

2. Draw the graph of following function:

z = e−2t cos(3t + 1) − π ≤ t ≤ 5π
The deection of a cantilever beam is the distance its end moves in response to a
force applied at the end. The following table gives the deection x that was
produced in a particular beam by the given applied force f. Plot the graph:
Force f (pound) 0 100 200 300 400 500 600 700 800

Deection x (inches) 0 0.09 0.18 0.28 0.37 0.46 0.55 0.65 0.74

S.M (IST) CSLab 32 / 32

You might also like