Main Content

crt

Chinese remainder theorem

Description

example

x= crt(res,div)returns the scalar integerxthat is congruent to each remainder inresfor the corresponding divisor indiv.xsatisfies

mod(x,div) =res.

In other words, dividingxby each element ofdivleaves as remainder the corresponding element ofres.

Examples

collapse all

Find a number that has a remainder of2when divided by9, a remainder of3when divided by10, and a remainder of6when divided by11.

x = crt([2 3 6],[9 10 11])
x = 83

Use themodfunction to verify the result.

ver = mod(x,[9 10 11])
ver =1×32 3 6

In a staggered pulse repetition frequency (PRF) radar system, the first PRF corresponds to70range bins and the second PRF corresponds to85range bins. The target is detected at bin47for the first PRF and bin12for the second PRF. Assuming each range bin is50meters, compute the target range from these two measurements.

idx = crt([47 12],[70 85]); r = 50*idx
r = 30350

Input Arguments

collapse all

Remainder array, specified as a row vector of nonnegative integers.resmust have the same number of elements asdiv.

Data Types:single|double

Divisor array, specified as a row vector of positive integers.divmust have the same number of elements asres.

Data Types:single|double

Output Arguments

collapse all

Congruent integer, returned as a scalar.

Extended Capabilities

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

版本嘘ory

Introduced in R2021a