0% found this document useful (0 votes)
20 views

Matlab 1

MATLAB is an interactive system for solving technical problems using matrix manipulation. It contains built-in functions for tasks like linear algebra, plotting, and data analysis. Users can access MATLAB through a desktop interface containing tools like the command window and workspace. Commands and syntax exist for tasks like defining variables, performing calculations, adding comments, and formatting output.

Uploaded by

hurairabaig37
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Matlab 1

MATLAB is an interactive system for solving technical problems using matrix manipulation. It contains built-in functions for tasks like linear algebra, plotting, and data analysis. Users can access MATLAB through a desktop interface containing tools like the command window and workspace. Commands and syntax exist for tasks like defining variables, performing calculations, adding comments, and formatting output.

Uploaded by

hurairabaig37
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

MATLAB

Introduction
• 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 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.
• 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.
Starting MATLAB
• After logging into your account, you can enter
MATLAB by double-clicking on the MATLAB
shortcut icon on your Windows desktop.
When you start MATLAB, a special window
called the MATLAB desktop appears. The
desktop is a window that contains other
windows. The major tools within or accessible
from the desktop are:
• The Command Window
• The Command History
• The Workspace
• The Current Directory
• The Help Browser
• The Start button
Quitting MATLAB
• To end your MATLAB session, type quit in the
Command Window
Adding Comments
• The percent symbol (%) is used for indicating a
comment line. For example,
• x = 9 % assign the value 9 to x
• You can also write a block of comments using
the block comment operators % { and % }.
String variables
• You can also assign strings of text to variables,
not just numbers, with single quotes (not
double
• quotes) around the text. For example:
• >> w = 'Good morning';
• w = Good morning
Error messages
• If we enter an expression incorrectly, MATLAB will
return an error message. For example,
In the following, we left out the multiplication sign *
• >> x = 10;
• >> 5x
• ??? 5x
• |
• Error: Unexpected MATLAB expression.
Colon operator
• Often we must deal with matrices or vectors
that are too large to enter one element at a
time. For example, suppose we want to enter
a vector x consisting of points
(0; 0.1; 0.2; 0.3; ---; 5). We can use the
command
• >> x = 0:0.1:5;
• The row vector has 51 elements.
Linear spacing
• On the other hand, there is a command to generate linearly spaced
vectors: linspace. It is similar to the colon operator (:), but gives
direct control over the number of points. For example,
• y = linspace(a,b)
• generates a row vector y of 100 points linearly spaced between and
including a and b.
• y = linspace(a,b,n)
• generates a row vector y of n points linearly spaced between and
including a and b. This is useful when we want to divide an interval
into a number of subintervals of the same length.
• For example,
• >> theta = linspace(0,2*pi,101)
• divides the interval [0; 2¼] into 100 equal subintervals, then
creating a vector of 101 elements.
The format Command
• By default, MATLAB displays numbers with four
decimal place values. This is known as short format.
• However, if you want more precision, you need to use
the format command.
• The format long command displays 16 digits after
decimal.
• For example:
• format long
• x = 7 + 10/3 + 5 ^ 1.2
• x =17.231981640639408
• format short
• x = 7 + 10/3 + 5 ^ 1.2
• x = 17.2320
• The format bank command rounds numbers
to two decimal places.
• x = 7 + 10/3 + 5 ^ 1.2
• x = 17.23
• MATLAB displays large numbers using
exponential notation.
• The format short e command allows displaying in
exponential form with four decimal places plus
the exponent.
For example,
• format short e
• 4.678 * 4.9
• ans = 2.2922e+01
• The format long e command allows displaying
in exponential form with four decimal places
plus the exponent. For example,
• format long e
• x = pi
• x = 3.141592653589793e+00
• The format rat command gives the closest
rational expression resulting from a
calculation. For example,
• 4.678 * 4.9
• ans = 2063/90

You might also like