Main Content

minus, -

Symbolic subtraction

Description

-A returns the negation of A.

example

A - B subtracts B from A and returns the result.

example

minus(A,B) is an alternate way to execute A - B.

example

Examples

Subtract Scalar from Array

Subtract 2 from array A.

syms x
A = [x 1;-2 sin(x)];
A - 2
ans =
[ x - 2,         -1]
[    -4, sin(x) - 2]

minus subtracts 2 from each element of A.

Subtract the identity matrix from matrix M:

syms x y z
M = [0 x; y z];
M - eye(2)
ans =
[ -1,     x]
[  y, z - 1]

Subtract Numeric and Symbolic Arguments

Subtract one number from another. Because these are not symbolic objects, you receive floating-point results.

11/6 - 5/4
ans =
    0.5833

Perform subtraction symbolically by converting the numbers to symbolic objects.

sym(11/6) - sym(5/4)
ans =
7/12

Alternatively, call minus to perform subtraction.

minus(sym(11/6),sym(5/4))
ans =
7/12

Subtract Matrices

Subtract matrices B and C from A.

A = sym([3 4; 2 1]);
B = sym([8 1; 5 2]);
C = sym([6 3; 4 9]);
Y = A - B - C
Y =
[ -11,   0]
[  -7, -10]

Use syntax -Y to negate the elements of Y.

-Y
ans =
[ 11,  0]
[  7, 10]

Subtract Functions

Subtract function g from function f.

syms f(x) g(x)
f = sin(x) + 2*x;
y = f - g
y(x) =
2*x - g(x) + sin(x)

Input Arguments

collapse all

Input, specified as a symbolic scalar variable, matrix variable, function, matrix function, expression, or vector, matrix, or array of symbolic scalar variables.

Input, specified as a symbolic scalar variable, matrix variable, function, matrix function, expression, or vector, matrix, or array of symbolic scalar variables.

Tips

  • All nonscalar arguments must have the same size. If one input argument is nonscalar, then minus expands the scalar into an array of the same size as the nonscalar argument, with all elements equal to the corresponding scalar.

Version History

Introduced before R2006a

expand all