Introduction to matlab

Matlab ia a very important software in the engineering world
In our university studying and practicing matlab depends in the student himself
here is a brief totorial (clear steps) to help you in using matlab 7.0 version

Part 1: MATLAB background

Introduction:-

MATLAB stands for
[LEFT]MATrix LABoratory, which is a powerful, high level language and a

technical computing environment that provides core mathematics and advanced graphical
tools for data analysis, visualization and algorithm development. MATLAB is intuitive
and easy to use since it follows many other programming languages like C. In MATLAB
every thing are matrices, matrix operations are programmed so that element-wise
operations or linear combinations are more efficient than loops over the array elements.
. How to start and quit?
Start: double click on the MATLAB icon on the desktop
[B][FONT=TimesNewRoman,Bold][SIZE=3]Quit:

[/left]
[/size][/font][/b][LEFT]to exit, type quit at the command promp

. Working with MATLAB
Once a MATLAB session is started there are two ways to work with:
- Command window
a. For small tasks like execution of a single command.
[B][FONT=TimesNewRoman,Bold][SIZE=3]b.

[/left]
[/size][/font][/b][LEFT]As a calculator for small calculations.

- M- files
a. Used for large programs and projects.[/left]

b. For funqctions.[FONT=TimesNewRoman,Bold][SIZE=3]

[/size][/font][LEFT]c. Known as m-file because of their .m extension.

Comments can be added to the m-file program or function to clarify the statements or
character % and they are colored in green automaticall.
. Getting help in MATLAB
MATLAB provides a very powerful and useful help and information on the commands
and how to use specific built-in functions.
a- Help function name: [/left]
[LEFT]Displays a brief description and the syntax for the function.

[B]:('b- Helpwin (‘function name

[/left]
[/b][LEFT]the difference is that the previous command displays

the information on the command window while the second command opens a
separate window called the ‘help browser’.
[B][FONT=TimesNewRoman,Bold][SIZE=3]:c- Lookfor

[/left]
[/size][/font][/b][LEFT]Helps in finding functions related to a particular topic, if you want to

know if MATLAB has a function for performing an operation but you don’t know
the exact correct name of the function.
. Matrix Manipulation
MATLAB is case sensitive i.e. ‘a’ and ‘A’ will be treated as two different variables.
The general structure of variables in MATLAB is a Matrix which is an m x n matrix
where m represents the number of rows and n represents the number of columns, but if
the variable has only one entry it will be a 1x1 matrix (Scalar), moreover if the matrix
(has only one row or one column then it is called (Vector
5.1 Creating matrix in MATLAB:
: By explicitly entering the elements: note the following:
- Separate the elements of a row with blank or commas.
- Use a semicolon to indicate new column.
- Surround the entire list of elements with square brackets.
Examples:
A = [1 2 3 4 5 6] % A is a row vector
X= [1 2 3 ; 4 5 6 ; 7 8 9 ] % X is a 3 by 3 matrix
Y = [0 ; 1 ; 3 ; 5] % Y is a column vector
B = [11] % B is a scalar
[FONT=TimesNewRoman,Bold][SIZE=3]B By generating sequence of numbers using colon operator[/b]

[/left]
[/size][/font][LEFT]. Define the initial,

final and increment values (lower limit: increment: upper limit), note that the default
value for the increment (in case it was not provided) is one.

Examples:
X = 1:10
Z = 0: 0.1: 20
[B][FONT=TimesNewRoman,Bold][SIZE=3] By using special built in functions

[/left]
[/size][/font][/b][LEFT]: There are several useful built in function that

can be used to generate vectors and matrices such as ZEROS, ONES, EYE, and RAND
Examples
- Use the Help to explore the above functions.
- Generate a row vector of zeros of size 15.
- What is the index of the fist element in the matrix (0 or 1)? Think!
. Functions
Functions also called m-files are widely used and make life easier while using MATLAB.
M-files group several commands that are stored in a text file with the extension .m and
can be used later as any normal built in function.
Example:
Write a MATLAB function RANDINT that generates random integral matrix.
RANDINT returns an m-by-n matrix with entries between 0 and 9.
[FONT=TimesNewRoman][SIZE=3][COLOR=#0000ff]function

[/left]
[/color][/size][/font][LEFT]a = randint(m,n) n[SIZE=3]

[/size]%RANDINT Randomly generated integral matrix.
% randint(m,n) returns an m-by-n such matrix with entries
% between 0 and 9.
a = floor(10*rand(m,n)) n
[FONT=SymbolMT][SIZE=3]•

[/left]

[FONT=TimesNewRoman][SIZE=3]-

[/left]
[/size][/font][LEFT]a is the output of the function.

m,n) are the inputs of the function).
- randint is the name of the function.
- The function should be saved as a file with the same name of the function name.

- Store the file containing the function definition in the work directory.

I hope you get benifit from this introduction
Allah yewaffa2kom