A Quick Tutorial on MATLAB
by: Ardyansyah nasution
MATLAB
MATLAB is a software package for doing numerical
computation. It was originally designed for solving linear
algebra type problems using matrices. It’s name is derived
from MATrix LABoratory.
MATLAB has since been expanded and now has built-in
functions for solving problems requiring data analysis, signal
processing, optimization, and several other types of scientific
computations. It also contains functions for 2-D and 3-D
graphics and animation.
MATLAB Variable names
Variable names are case sensitive.
Variable names can contain up to 63 characters ( as of
MATLAB 6.5 and newer).
Variable names must start with a letter and can be followed by
letters, digits and underscores.
Examples :
>> x = 2;
>> abc_123 = 0.005;
>> 1ab = 2;
Error: Unexpected MATLAB expression
MATLAB Special Variables
pi Value of π
eps Smallest incremental number
inf Infinity
NaN Not a number e.g. 0/0
i and j i = j = square root of -1
realmin The smallest usable positive real number
realmax The largest usable positive real number
MATLAB Relational operators
MATLAB supports six relational operators.
Less Than <
Less Than or Equal <=
Greater Than >
Greater Than or Equal >=
Equal To ==
Not Equal To ~= (NOT != like in C)
MATLAB Logical Operators
MATLAB supports three logical operators.
not ~ % highest precedence
and & % equal precedence with or
or | % equal precedence with and
Matrices and MATLAB
MATLAB Matrices
MATLAB treats all variables as matrices. For our purposes a
matrix can be thought of as an array, in fact, that is how it is
stored.
Vectors are special forms of matrices and contain only one
row OR one column.
Scalars are matrices with only one row AND one column
Generating Matrices
A scalar can be created in MATLAB as follows:
>> x = 23;
A matrix with only one row is called a row vector. A row vector
can be created in MATLAB as follows (note the commas):
>> y = [12,10,-3]
y =
12 10 -3
A matrix with only one column is called a column vector. A
column vector can be created in MATLAB as follows:
>> z = [12;10;-3]
z =
12
10
-3
Generating Matrices
MATLAB treats row vector and column vector very differently
A matrix can be created in MATLAB as follows (note the
commas and semicolons)
>> X = [1,2,3;4,5,6;7,8,9]
X =
1 2 3
4 5 6
7 8 9
Matrices must be rectangular!
Tidak ada komentar:
Posting Komentar