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

Image Analyst
Image Analyst 2014년 1월 16일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Roger Stafford
Roger Stafford 2014년 1월 16일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

질문:

2014년 1월 15일

답변:

2014년 1월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by