Question about constraints in optimization problems

조회 수: 1 (최근 30일)
Rahim Rahim
Rahim Rahim 2020년 11월 29일
댓글: Walter Roberson 2020년 11월 29일
I have the following victor:
A=[ 0.1 0.1 0.3 0.2 0.3]
The sum of this vector is 1, but when I try the following code:
Test = (sum(A(:)) ==1)
If ( Test == 1 )
"True"
Else
"False"
The results is always FALSE.
What is the problem

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 11월 29일
편집: Ameer Hamza 2020년 11월 29일
This is due to the finite precision of floating-point numbers. Calculations on floating points numbers can accumulate errors, so the value is not exactly equal to one. You need to allow a bit of tolerance in comparing floating-point values. For example
Test = (sum(A(:)) ==1)
if ( abs(Test-1) < 1e-6 )
"True"
else
"False"
end
  댓글 수: 3
Rahim Rahim
Rahim Rahim 2020년 11월 29일
편집: Rahim Rahim 2020년 11월 29일
@Walter Roberson thank you for your comment
Any part should I see ?
Walter Roberson
Walter Roberson 2020년 11월 29일
All of the section on the topic.

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

카테고리

Help CenterFile Exchange에서 Quadratic Programming and Cone Programming에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by