# ones() Function & Examples

Use the ones() matrix function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## ones

#### ones(m)

#### ones(m, n)

#### ones(m, n, p, ...)

#### ones([m])

#### ones([m, n])

#### ones([m, n, p, ...])

Try it yourself:

```calculio
ones(3)
ones(3, 5)
ones([2,3]) * 4.5
a = [1, 2, 3; 4, 5, 6]
ones(size(a))
```

[concat](https://calcul.io/function/concat/index.md)

[det](https://calcul.io/function/det/index.md)

[diag](https://calcul.io/function/diag/index.md)

[identity](https://calcul.io/function/identity/index.md)

[inv](https://calcul.io/function/inv/index.md)

[range](https://calcul.io/function/range/index.md)

[size](https://calcul.io/function/size/index.md)

[squeeze](https://calcul.io/function/squeeze/index.md)

[subset](https://calcul.io/function/subset/index.md)

[trace](https://calcul.io/function/trace/index.md)

[transpose](https://calcul.io/function/transpose/index.md)

[zeros](https://calcul.io/function/zeros/index.md)

---

## ones(): create a matrix filled with one

**ones(n)**, or ones with dimensions, creates an array or matrix whose entries are all 1. It is a convenient starting point for weights, offsets, test fixtures, and matrix formulas.

## Examples

`ones(3)` creates a length-three vector of ones; supplying two dimensions creates a rectangular matrix. Add or multiply it with another matrix when every position needs the same adjustment.

## Matrix companions

Use [zeros()](https://calcul.io/function/zeros/index.md) for a zero-filled structure, [identity()](https://calcul.io/function/identity/index.md) for an identity matrix, and [size()](https://calcul.io/function/size/index.md) to verify shape. Combine with [multiply()](https://calcul.io/function/multiply/index.md) or [add()](https://calcul.io/function/add/index.md) in matrix expressions.

## Shape matters

Dimensions should be non-negative integers. Match shapes before elementwise operations to avoid broadcasting or dimension errors.

[All functions](https://calcul.io/functions/index.md)
