# coincidence

Coincidence algorithm

Since R2021a

## Syntax

``x = coincidence(res,div,maxval)``
``x = coincidence(res,div,maxval,tol)``

## Description

example

````x = coincidence(res,div,maxval)` returns the scalar `x` that is less than or equal to `maxval` and is congruent to each remainder in `res` for the corresponding divisor in `div`. `x` satisfies mod(`x`,`div`) = `res`.In other words, dividing `x` by each element of `div` leaves as remainder the corresponding element of `res`.```
````x = coincidence(res,div,maxval,tol)` also specifies the tolerance. In practice, there may be no value that satisfies all constraints in `res` and `div` exactly. In that case, `coincidence` identifies a set of candidates that approximately satisfy the constraints and are within an interval of width 2 × `tol` centered at the candidates' median. The function then returns the median as `x`.```

## Examples

collapse all

Find a number smaller than `1000` that has a remainder of about `12` when divided by `19`, a remainder of about `13.1` when divided by `20.4`, and a remainder of about `6.1` when divided by `11`.

There is no number that satisfies the constraints exactly, so specify a tolerance of `1`.

```rems = [12 13.1 6.1]; divs = [19 20.4 11]; tol = 1; x = coincidence(rems,divs,1000,tol)```
```x = 809.1000 ```

Verify that the true remainders are within the specified tolerance.

`tr = x - floor(x./divs).*divs`
```tr = 1×3 11.1000 13.5000 6.1000 ```

Repeat the computation, but now specify a tolerance of `3`. The number that satisfies the constraints decreases as the tolerance increases.

```tol = 3; x = coincidence(rems,divs,1000,tol)```
```x = 31 ```
`tr = x - floor(x./divs).*divs`
```tr = 1×3 12.0000 10.6000 9.0000 ```

Increase the tolerance to `6`. The tolerance has to be smaller than the smallest specified remainder.

```tol = 6; x = coincidence(rems,divs,1000,tol)```
```x = 12 ```
`tr = x - floor(x./divs).*divs`
```tr = 1×3 12 12 1 ```

In a staggered pulse repetition frequency (PRF) radar system, the first PRF corresponds to `70` range bins and the second PRF corresponds to `85` range bins. The target is detected at bin `47` for the first PRF and bin `12` for the second PRF. Assuming each range bin is `50` meters, compute the target range from these two measurements. Assume the farthest target can be `50` km away.

```idx = coincidence([47 12],[70 85],50e3/50); r = 50*idx```
```r = 30350 ```

## Input Arguments

collapse all

Remainder array, specified as a row vector of nonnegative numbers. `res` must have the same number of elements as `div`.

Data Types: `single` | `double`

Divisor array, specified as a row vector of positive numbers. `div` must have the same number of elements as `res`.

Data Types: `single` | `double`

Upper bound, specified as a positive scalar.

Data Types: `single` | `double`

Tolerance, specified as a nonnegative scalar. `tol` must be smaller than the smallest element of `res`.

Data Types: `single` | `double`

## Output Arguments

collapse all

Congruent value, returned as a scalar.

## Version History

Introduced in R2021a