Main Content

coincidence

Coincidence algorithm

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 2 when divided by 9, a remainder of 3 when divided by 10.4, and a remainder of 6.3 when divided by 11.

There is no number that satisfies the constraints exactly, so specify a tolerance of 1. coincidence identifies a set of numbers that approximately satisfy the constraints and are within 2×tol=2 from their median. The function then outputs the median.

tol = 1;

x = coincidence([2 3 6.3],[9 10.4 11],1000,tol)
x = 127.8000

Increase the tolerance to 2.

tol = 2;

x = coincidence([2 3 6.3],[9 10.4 11],1000,tol)
x = 74

Specify a tolerance of 3.3. Any tolerance larger than this value results in the same answer.

tol = 3.3;

x = coincidence([2 3 6.3],[9 10.4 11],1000,tol)
x = 3

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 integers. 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.

Data Types: single | double

Output Arguments

collapse all

Congruent value, returned as a scalar.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

See Also

|

Introduced in R2021a