# times, .*

Symbolic array multiplication

## Syntax

``A.*B``
``times(A,B)``

## Description

example

````A.*B` performs elementwise multiplication of `A` and `B`.```
````times(A,B)` is equivalent to `A.*B`.```

## 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 elementwise 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)```

## Input Arguments

collapse all

Input, specified as a number or a symbolic number, variable, vector, matrix, multidimensional array, function, or expression. Inputs `A` and `B` must be the same size unless one is a scalar. A scalar value expands into an array of the same size as the other input.

Input, specified as a number or a symbolic number, variable, vector, matrix, multidimensional array, function, or expression. Inputs `A` and `B` must be the same size unless one is a scalar. A scalar value expands into an array of the same size as the other input.