times, .*
Symbolic array multiplication
Syntax
Description
Examples
Multiply Matrix by Scalar
Create a 2
-by-3
matrix.
A = sym('a', [2 3])
A = [ a1_1, a1_2, a1_3] [ a2_1, a2_2, a2_3]
Multiply the matrix by the symbolic expression sin(b)
.
Multiplying a matrix by a scalar means multiplying each element of the matrix by
that scalar.
syms b A.*sin(b)
ans = [ a1_1*sin(b), a1_2*sin(b), a1_3*sin(b)] [ a2_1*sin(b), a2_2*sin(b), a2_3*sin(b)]
Multiply Two Matrices
Create a 3
-by-3
symbolic Hilbert matrix and a 3
-by-3
diagonal matrix.
H = sym(hilb(3)) d = diag(sym([1 2 3]))
H = [ 1, 1/2, 1/3] [ 1/2, 1/3, 1/4] [ 1/3, 1/4, 1/5] d = [ 1, 0, 0] [ 0, 2, 0] [ 0, 0, 3]
Multiply the matrices by using the element-wise multiplication operator
.*
. This operator multiplies each element of the first matrix
by the corresponding element of the second matrix. The dimensions of the matrices
must be the same.
H.*d
ans = [ 1, 0, 0] [ 0, 2/3, 0] [ 0, 0, 3/5]
Multiply Expression by Symbolic Function
Multiply a symbolic expression by a symbolic function. The result is a symbolic function.
syms f(x) f(x) = x^2; f1 = (x^2 + 5*x + 6).*f
f1(x) = x^2*(x^2 + 5*x + 6)