Arithmetic to ensure positives

Hello all:
I am looking for a simple logic to ensure 'positive' for multiple variables. In pseudo code terms want to replace
if {(a-b>=0).and.(c-d>=0).and.(e-f>=0) then...}
without the use of boolean 'and' or special functions like max. Pure arithmetic will be much helpful.
My inspiration is
(a-b)^2 + (c-d)^2 + (e-f)^2 = 0
which uniquely ensures/enforces eqalities, a=b, c=d, e=f.
Any parallels.
Much appreciated.
Regards.

답변 (2개)

Walter Roberson
Walter Roberson 2015년 12월 27일

0 개 추천

This is not possible to do without at least one comparison, and comparisons are not pure arithmetic. Your inspiration (a-b)^2 + (c-d)^2 + (e-f)^2 = 0 involves a comparison and so is not pure arithmetic.

댓글 수: 5

Amit
Amit 2015년 12월 27일
Hello Walter. Thanks. I meant to say 'pure arithmetic' in the sense of avoiding special functions like Max, Min, Absolute.
'Simple', non-exotic comparisons might work.
I ask for this because my optimization scheme is very fragile.
Thanks.
Image Analyst
Image Analyst 2015년 12월 27일
I can't think of any legitimate reason why someone would want to write a program that doesn't allow boolean relational operators like >= and &&. Aside from whether it's even possible, why would you want to torture yourself like that? So your scheme is fragile - make it non-fragile and get on with things.
Note that your "target" idea,
(a-b)^2 + (c-d)^2 + (e-f)^2 = 0
is actually a terribly written thing in terms of numerical analysis. Sorry, but that is a bad thing to do when you might be working with floating point numbers.
As Image Analyst says, just write some basic code that does what you want instead of looking for some elegant (to you) code fragment that looks nice, but does bad things.
Walter Roberson
Walter Roberson 2015년 12월 27일
When you say that your optimization scheme is very fragile, are you talking about attempting to code constraints in a manner that is differentiable?
Amit
Amit 2016년 1월 3일
Yes actually Walter. In deed, hoping for that. Thanks in deed for bringing me closer to asking proper question here.
In the last few days, I tried in built GRG Non Linear Scheme with 'min' function, as a work around. Hoping to do something better.
Thanks for your attention.

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

Walter Roberson
Walter Roberson 2016년 1월 4일

0 개 추천

(a-b)^2 + (c-d)^2 + (e-f)^2 = 0 is differentiable only because it is smoothly invertible, that it can be translated into a series of variable reductions. Inequalities cannot be inverted that way. You cannot even code a > 0 invertibly -- if you could then c>=d could be coded as (c-d)^2 - delta_c = 0 together with however you coded delta_c > 0.
Unless, that is, you are okay with coding Heaviside functions, in which delta_c > 0 translates to Heaviside(delta_c) - 1 = 0 after having defined Heaviside(0) as 0 (Heaviside(0) does not have a fixed value, not really; one of the common conventions says Heaviside(0) = 1/2).
But diff(Heaviside(delta_c),delta_c) is Dirac(delta_c) and that is considered a distribution rather than a particular value, definitely not continuously differentiable. I would not consider it suitable for the use in this situation, but perhaps the theory of GRG is more flexible than I am.

댓글 수: 1

Amit
Amit 2016년 1월 4일
Dear Walter:
Thanks much. I learnt a few things from you answer. I understood what you are saying. Though this is pushing my problem in 'high mathematics' rather than come out of it.
Perhaps what I asked is not available, but let me seek a little bit more by keeping it still as an open question.
Meanwhile, the GRG scheme in deed appears to be accommodating.
Look forward to more thoughts, if any.
Regards, Amit

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2015년 12월 26일

댓글:

2016년 1월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by