
Unterabschnitte
Matlab works with essentially one kind of
object: a matrix of numbers (which could include complex elements).
Scalars are 1by1 matrices, while vectores are 1byn or
nby1 matrices.
When entering a matrix, seperate columns by spaces or commas and
rows by semicolons, e.g.:
>> P = [3 5 6 1; 2 5 4 9]
P =
3 5 6 1
2 5 4 9
Matlab stores the above 2by4 matrix in its
workspace for later use. To retrieve a variable, simply type its
name (e.g., P). Matlab is casesensitive, so
p and P are not the
same.
When you do not specify an output variable, Matlab uses the
variable ans, short for answer, to store the
results of a calculation.
Including a semicolon (;) at the end of a command suppresses
Matlab's echoing to the teminal (this is useful when dealing with
large sets of numbers.)
To take the sum along the columns of P
type
>> sum(P)
ans =
1 10 2 10
Matlab has a preference for working with the
columns of a matrix, so the easiest way to get the row sums is to
transpose the matrix with the transpose operator .', compute the column sums of the transpose, and then
transpose the result:
>> sum(P.').';
In contrast single quote operator ' conjugates and transposes matrices (Hermitian
operator).
The element in row i
and column j of P is
denoted by P(i,j). If you try to use the value
of an element outside of the matrix, it is an error.
>> t = P(4,5)
Index exceeds matrix dimensions.
On the other hand, if you store a value in an
element outside of the matrix, the size increases to accommodate
the newcomer.
>> X = P; X(1,5) = 17
X =
3 5 6 1 17
2 5 4 9 0
It is also possible to refer to the elements
of a matrix with a single subscript, P(5). In this case the array
is regarded as one long column vector formed from the columns of
the original matrix.
>> P(5)
ans =
6
Matlab provides mathematical expressions that
involve entire matrices. The building blocks of expressions are
variables, numbers, operators and
functions.
Matlab does not require any type declarations or dimension
statements for variables. Variable names consist of a
letter, followed by any number of letters, digits, or underscores.
Matlab uses only the first 31 characters of a variable name.
Expressions use familiar arithmetic operators and precedence
rules: + addition,  subtraction, * multiplication, / division,
left
division (described in Matrices and Linear Algebra in the MATLAB
documentation), ^ power, ' complex conjugate transpose
and ( ) specify evaluation order. The mathematical operations
defined on matrices are the subject of linear algebra. The
multiplication symbol, *, denotes the matrix multiplication
involving inner products between rows and columns:
>> w = [0.5 1]; h = w*P
h =
0.5000 7.5000 1.0000 9.5000
Matlab uses conventional decimal notation,
with an optional decimal point and leading plus or minus sign, for
numbers. Scientific notation uses the letter e to specify a
poweroften scale factor. Imaginary numbers use either i or j as a
suffix. All numbers are stored internally using the long format
specified by the IEEE floatingpoint standard.
Matlab provides a large number of standard elementary mathematical
functions as well as more advanced mathematical functions,
including Bessel and gamma functions. Some of the functions, like
sqrt and sin or
pi 3.14159265...
i Imaginary unit,
j Same as i
Inf Infinity
NaN Notanumber
are built in. Other functions, like gamma, sinh or hardlim, are implemented in Mfiles. You can see the
code, e.g. by typing
>> type hardlim
and even modify it if you want.
