Main Content
plus, +
Symbolic addition
Description
Examples
Add Scalar to Array
plus
adds x
to each element of the
array.
syms x A = [x sin(x) 3]; A + x
ans = [ 2*x, x + sin(x), x + 3]
Add Two Matrices
Add the identity matrix to matrix
M
.
syms x M = [x x^2;Inf 0]; M + eye(2)
ans = [ x + 1, x^2] [ Inf, 1]
Alternatively, use plus(M,eye(2))
.
plus(M,eye(2))
ans = [ x + 1, x^2] [ Inf, 1]
Add Symbolic Functions
syms f(x) g(x) f(x) = x^2 + 5*x + 6; g(x) = 3*x - 2; h = f + g
h(x) = x^2 + 8*x + 4
Add Expression to Symbolic Function
Add expression expr
to function f
.
syms f(x) f(x) = x^2 + 3*x + 2; expr = x^2 - 2; f(x) = f(x) + expr
f(x) = 2*x^2 + 3*x
Input Arguments
Tips
All nonscalar arguments must be the same size. If one input argument is nonscalar, then
plus
expands the scalar into an array of the same size as the nonscalar argument, with all elements equal to the scalar.