Professional Documents
Culture Documents
Introduction to MATLAB
Objective
Applications of MATLAB
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.
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.
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
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.
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;
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
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
1.8. Exercise
1. Find the solution to the following set of equations using the matrix inverse and left and right
division.
Solution
2. Find the solution to the following set of equations using the matrix inverse and left and right
division.
Solution