GCD search for non-integers

Does someone know how to solve this problem?
Find the approximation of greatest common divisor for a set of data (a vector of noninteger
numbers). In general, these will not have an exact common divisor. The solution
(also a floating point number) should be approximated with certain accuracy. E.g.:
x = [3.3308 4.4449 7.7828 12.2273 14.4405 21.1161];
epsilon = 0.01;
d = find_gcd(x,epsilon)
d =
1.1111
% verifying result
x/d
ans =
2.9978 4.0005 7.0046 11.0046 12.9966 19.0047
error = x/d round(x/d)
error =
-0.0022 0.0005 0.0046 0.0046 -0.0034 0.0047

1 comentario

Image Analyst
Image Analyst el 16 de En. de 2014
Any number can divide those numbers. I think you need to add the requirement that after division, the result is within epsilon of an integer . Otherwise, yeah, you can divide any of those numbers by 500 bazillion and get another floating point number.

Iniciar sesión para comentar.

Respuestas (1)

Roger Stafford
Roger Stafford el 16 de En. de 2014

0 votos

I see a way to do your problem provided it is assumed that each number in x must round to a non-zero integer. It would involve examining in order of decreasing magnitude the various values of a potential divisor at each point where one of the quantities in x divided by that divisor either enters or leaves an allowed epsilon interval about a non-zero integer. Since this looks like a homework problem I'll stop with that hint.

Categorías

Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.

Preguntada:

el 15 de En. de 2014

Respondida:

el 16 de En. de 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by