Matrices and Matrix Operations - Pdf 62


10
You can use the menus and buttons in the Current
Directory window to peruse your files, or you can use
commands typed in the Command window. The
command
pwd
returns the name of the current directory,
and
cd
will change the current directory. The command
dir
lists the contents of the working directory, whereas
the command
what
lists only the MATLAB-specific files
in the directory, grouped by file type. The MATLAB
commands
delete
and
type
can be used to delete a file
and display a file in the Command window, respectively.
The Current Directory window includes a suite of useful
code development tools, described in Chapter 21.
3. Matrices and Matrix Operations
You have now seen most of MATLAB’s windows and
what they can do. Now take a look at how you can use
MATLAB to work on matrices and other data types.
3.1 Referencing individual entries
Individual matrix and vector entries can be referenced

is
m
-by-
n
, then
A(i,j)
is the same as
A(i+(j-1)*m)
. This feature is
most often used with the
find
function (see Section 5.6).
3.2 Matrix operators
The following matrix operators are available in
MATLAB:
+
addition or unary plus
-
subtraction or negation
*
multiplication
^
power
'
transpose (real) or conjugate transpose (complex)
.'
transpose (real or complex)
\
left division (backslash or
mldivide

inner (or dot) product, and
x*y'
is their outer (or cross)
product. Try these commands:
y = [1 2 3]'
x'*y
x*y'
3.3 Matrix division (slash and
backslash)
The matrix “division” operations deserve special
comment. If
A
is an invertible square matrix and
b
is a
compatible column vector, or respectively a compatible
row vector, then
x=A\b
is the solution of
A*x=b
, and
x=b/A
is the solution of
x*A=b
. These are also called the
backslash (
\
) and slash operators (
/
); they are also

A
is not square, the under- or over-
determined system is solved in the least squares sense.
Right division is defined in terms of left division by
b/A

=

(A'\b')'
. Try this:
A = [1 2 ; 3 4]
b = [4 10]'
x = A\b
The solution to
A*x=b
is the column vector
x=[2;1]
.

13
Backslash is a very powerful general-purpose method for
solving linear systems. Depending on the matrix, it
selects forward or back substitution for triangular
matrices (or permuted triangular matrices), Cholesky
factorization for symmetric matrices, LU factorization for
square matrices, or QR factorization for rectangular
matrices. It has a special solver for Hessenberg matrices.
It can also exploit sparsity, with either sparse versions of
the above list, or special-case solvers when the sparse
matrix is diagonal, tridiagonal, or banded. It selects the

.
3.5 Relational operators
The relational operators in MATLAB are:

14
<
less than
>
greater than
<=
less than or equal
>=
greater than or equal
==
equal
~=
not equal
They all operate entry-wise. Note that
=
is used in an
assignment statement whereas
==
is a relational operator.
Relational operators may be connected by logical
operators:
&
and
|
or
~

3

<

5,

3

>

5,

3

==

5
, and
3

==

3
. When applied to matrices of the
same size, the result is a matrix of ones and zeros giving
the value of the expression between corresponding
entries. You can also compare elements of a matrix with
a scalar. Try:
A = [1 2 ; 3 4]
A >= 2


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status