sum 100 from given values and limits

조회 수: 1 (최근 30일)
Cristiano df
Cristiano df 2013년 10월 10일
댓글: Cristiano df 2013년 10월 11일
Hi all, I'd like to find values that sum 100 between these 4 values and their limits:
low high
31.5 33.4
15.3 16.8
47.2 49.1
3.0 3.7
For example a solution could be:
32.0
15.3
49.0
3.7
-------
100
Please help me ;)
Cristiano.
  댓글 수: 1
Matt Kindig
Matt Kindig 2013년 10월 10일
편집: Matt Kindig 2013년 10월 10일
There are an infinite number of solutions to this problem. Do you just need one that works (i.e., a feasible solution)?

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

채택된 답변

Roger Stafford
Roger Stafford 2013년 10월 10일
I propose the following unique "canonical" solution. Let 'low' and 'high' be vectors of your lower and upper range limits respectively and let s be the desired sum.
t = (s-sum(low))/(sum(high)-sum(low));
if t<0|t>1
error('No solution is possible')
else
v = low+t*(high-low);
end
If a solution is possible, elements of the vector 'v' will lie in the proper range and sum to the value s (except for very small round-off errors, of course.)
  댓글 수: 1
Cristiano df
Cristiano df 2013년 10월 11일
Thanks all for replies! I would not be able to find a solution without your help.
Many many thanks
Cristiano.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 10월 10일
Do you have an array that you're checking to see if its elements are in any one of those 4 ranges? Probably none of them will sum exactly to 100. See the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F YOu can either go greater than 100 or within some tolerance of 100 like the FAQ shows.

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by