You are on page 1of 9

LAB 01

Introduction to MATLAB
Objective

 Introduction to MATLAB, its functions and applications. (Part 01)

1.1. Introduction to MATLAB & its interference


The name MATLAB stands for Matrix Laboratory. MATLAB was written originally to provide
easy access to matrix software developed by the LINPACK (linear system package) and
EISPACK (Eigen system package) projects. MATLAB is a high-performance language for
technical computing. It integrates computation, visualization, and programming environment.
Furthermore, MATLAB is a modern programming language environment: it has sophisticated
data structures, contains built-in editing and debugging tools, and supports object-oriented
programming. These factors make MATLAB an excellent tool for teaching and research.
MATLAB has many advantages compared to conventional computer languages (e.g., C,
FORTRAN) for solving technical problems. MATLAB is an interactive system whose basic data
element is an array that does not require dimensioning. The software package has been
commercially available since 1984 and is now considered as a standard tool at most universities
and industries worldwide. It has powerful built-in routines that enable a very wide variety of
computations. It also has easy to use graphics commands that make the visualization of results
immediately available. Specific applications are collected in packages referred to as toolbox.
There are toolboxes for signal processing, symbolic computation, control theory, simulation,
optimization, and several other fields of applied science and engineering.

Applications of MATLAB

 Math and computation, Algorithm development.


 Modeling, simulation, and prototyping.
 Data analysis, exploration, and visualization.

It involves mechanical engineering, electronic engineering, and computer science to name a few
to create robots or human-like machines. Robotics researchers and engineers use MATLAB to
design and tune algorithms, model real-world systems, and automatically generate code – all
from one software environment.

Control Engineering Lab


LAB 01

 Starting MATLAB

Start MATLAB by clicking on it in the Start menu. Once the program is running, you will see a
screen similar to Figure below;

The Command Window: is where you type commands. Hit Enter to run the command you just
typed.

The Current Directory: shows the directory that you are working in. This directory is where
MATLAB expects to find your files (M-files, audio, images, etc.). If you encounter a ‘file not
found’ error, it means the file is not in your Current Directory. You can change the working
directory by typing into it or clicking through the file browser.

The Workspace Window: displays information about all the variables that are currently active.
In particular, it will tell you the type (int, double, etc.) of variable, as well as the dimensions of
the data structure (such as a 2x2 or 8000x1 matrix). This information can be extremely useful for
debugging!

The Command History Window: keeps track of the operations that you’ve performed recently.
This is handy for keeping track of what you have or haven’t already tried.

Control Engineering Lab


LAB 01

Editor: The MATLAB Editor Window is a simple text editor where you can load, edit and save
complete MATLAB programs. The Editor window also has a menu command (Debug/Run)
which allows you to submit the program to the command window

1.2. Entering Commands and Creating Variables


To create a new variable, enter the variable name in the Command Window, followed by an
equal sign (=) and the value you want to assign to the variable.

Control Engineering Lab


LAB 01

1.3. Complex Data Types


A complex data type is usually a composite of other existing data types. For example, you might
create a complex data type whose components include built-in types, opaque types, distinct
types, or other complex types. An important advantage that complex data types have over user-
defined types is that users can access and manipulate the individual components of a complex
data type.

The following MATLAB code declares several local complex variables. x and y are declared by
complex constant assignment; z is created using the using the complex() function.

1.4. Analyzing and solving Vectors and Matrices


A vector is an object that has both a magnitude and a direction. Geometrically, we can picture
a vector as a directed line segment, whose length is the magnitude of the vector and with an
arrow indicating the direction.

In mathematics, a matrix is a rectangular array or table of numbers, symbols, or expressions,


arranged in rows and columns.

Control Engineering Lab


LAB 01

1.5. Mathematical operations on Vectors and Matrices

As far as linear algebra is concerned, the two most important operations with vectors are vector
addition [adding two (or more) vectors] and scalar multiplication (multiplying a vector by a
scalar). Analogous operations are defined for matrices. Matrices can be added or subtract
depend upon the size of each matrix. Some mathematical operation are done on MATLAB as
shown in figure below;

Control Engineering Lab


LAB 01

1.6. Some Important and commonly used Matrices


The MATLAB environment uses the term matrix to indicate a variable containing real or
complex numbers arranged in a two-dimensional grid. An array is, more generally, a vector,
matrix, or higher dimensional grid of numbers. All arrays in MATLAB are rectangular, in the
sense that the component vectors along any dimension are all the same length. The mathematical
operations defined on matrices are the subject of linear algebra.

1.7. Solving Simultaneous Linear Equations


Two linear equations in two variables taken together are called simultaneous linear equations.

The solution of system of simultaneous linear equation is the ordered pair (x, y) which satisfies
both the linear equations.

There are different methods are exits to solve linear equation in MATLAB, some are given
below;

Inverse method: The inverse matrix method uses this matrix equation to find the solution to the
system of equations directly.

−1
X =A B

Control Engineering Lab


LAB 01

Adj ( A )
A−1=
det ( A )

Left division: Left division is used to solve the matrix equation AX= B. In this equation X and B
are column vectors. This equation can be solved by multiplying, on the left, both sides by the
inverse of A:

X =A −1∗B

In MATLAB the last equation can be written by using the left division character:

X =A ¿

Right division: The right division is used to solve the matrix equation XR = D. In this equation
X and D are row vectors. This equation can be solved by multiplying, on the right, both sides by
the inverse of R:

−1
X =D∗R

In MATLAB the last equation can be written using the right division character: X=D/R

X =D/ R

Control Engineering Lab


LAB 01

1.8. Exercise
1. Find the solution to the following set of equations using the matrix inverse and left and right
division.

Solution

Control Engineering Lab


LAB 01

2. Find the solution to the following set of equations using the matrix inverse and left and right
division.

Solution

Control Engineering Lab

You might also like