matlab加、减、乘、除符号运算
2013-01-29 06:41阅读:
A\B=inv(A)*b 等同于 A除以B
MATLAB提供了常用的算术运算符:+,-, ,∕(﹨),^(幂指数)。
应该注意:(∕)右除法和(﹨)左除法这两种符号对数值操作时,其结果相同,其斜线下为分母,如1∕4与4﹨1,其结果均为0.25,但对矩阵操作时,左、右除法是有区别的。
Arithmetic Operators + - * / \ ^ '
Matrix and array arithmetic
Syntax
A+B
A-B
A*B
A.*B
A/B
A./B
A\B
A.\B
A^B
A.^B
A'
A.'
Description
MATLAB
®
software has two different types of arithmetic operations. Matrix
arithmetic operations are defined by the rules of linear algebra.
Array arithmetic operations are carried out element by element, and
can be used with multidimensional arrays. The period character
(
.) distinguishes the array ope
rations from the matrix operations. However, since the matrix and
array operations are the same for addition and subtraction, the
character pairs
.+ and
.- are not used.
+
Addition or unary
plus.
A+B adds
A and
B.
A and
B must have the same size, unless one is a scalar. A
scalar can be added to a matrix of any size.
-
Subtraction or
unary minus.
A-B subtracts
B from
A.
A and
B must have the same size, unless one is a
scalar. A scalar can be subtracted from a matrix of any size.
*
Matrix multiplication.
C = A*B is the linear algebraic product of the
matrices
A and
B. More precisely,
For nonscalar
A and
B, the number of columns of
A must equal the number of rows of
B. A scalar
can multiply a matrix of any size.
.*
Array multiplication.
A.*B is the element-by-element product of the arrays
A and
B.
A and
B must have the
same size, unless one of them is a scalar.
/
Slash or matrix right
division.
B/A is roughly the same as
B*inv(A).
More precisely,
B/A = (A'\B')'. See the reference page for
for more information.
./
Array right division.
A./B is the matrix with elements
A(i,j)/B(i,j).
A and
B must have the same size, unless one of
them is a scalar.
\
Backslash or matrix left
division. If
A is a square matrix,
A\B is roughly
the same as
inv(A)*B, except it is computed in a different
way. If
A is an
n-by-
n matrix and
B is a column vector with
n components, or a
matrix with several such columns, then
X = A\B is the
solution to the equation
AX = B. A warning message is
displayed if
A is badly scaled or nearly singular. See the
reference page for for more information.
If
A is an
m-by-
n matrix with
m ~=
n and
B is a column vector with
m
components, or a matrix with several such columns, then
X =
A\B is the solution in the least squares sense to the under-
or overdetermined system of equations
AX = B. The
effective rank,
k, of
A is determined from the QR
decomposition with pivoting (see for details). A solution
X is computed that has at most
k nonzero
components per column. If
k < n, this is usually not
the same solution as
pinv(A)*B, which is the least squares
solution with the smallest norm .
.\
Array left division.
A.\B is the matrix with elements
B(i,j)/A(i,j).
A and
B must have the same size, unless one of
them is a scalar.
^
Matrix power.
X^p
is
X to the power
p, if
p is a scalar.
If
p is an integer, the power is computed by repeated
squaring. If the integer is negative,
X is inverted first.
For other values of
p, the calculation involves
eigenvalues and eigenvectors, such that if
[V,D] = eig(X),
then
X^p = V*D.^p/V.
If
x is a scalar and
P is a matrix,
x^P
is
x raised to the matrix power
P using
eigenvalues and eigenvectors.
X^P, where
X and
P are both matrices, is an error.
.^
Array power.
A.^B
is the matrix with elements
A(i,j) to the
B(i,j)
power.
A and
B must have the same size, unless
one of them is a scalar.
'
Matrix transpose.
A' is the linear algebraic transpose of
A. For
complex matrices, this is the complex conjugate transpose.
.' Array transpose.
A.' is the array
transpose of
A. For complex matrices, this does not
involve conjugation.