Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to express logarithm function by a pre-calculated table and a binary variable

0 views
Skip to first unread message

Mengxiao Wu

unread,
Feb 15, 2006, 12:56:44 PM2/15/06
to
My objective function includes logarithm part. log(x+1). I want to use
a pre-calculated table and a binary variable y to replace it. That
means the table is z --> log(z+1). If (x=z) then (y=1), else (y=0). I
do not know how to use inequal equations to express "If (x=z) then
(y=1), else (y=0)."
Who can help me? Thanks a lot!!!!

e p chandler

unread,
Feb 15, 2006, 5:24:47 PM2/15/06
to

Well if x and z are floating point (real) numbers then you *do not*
want to compare them using .EQ. (OR ==).

Let eps be a real constant set to some small tolerance.

if abs(z-x)<eps then
y=1
else
y=0
end if


You may wish to express this as an indicator function which returns 0
or 1.

* Yes there are other fancy ways to do this but they remind me of "C".
*

-- Elliot

Michael Metcalf

unread,
Feb 15, 2006, 5:29:42 PM2/15/06
to

"e p chandler" <ep...@juno.com> wrote in message
news:1140042287.7...@f14g2000cwb.googlegroups.com...

> Mengxiao Wu wrote:
>> My objective function includes logarithm part. log(x+1). I want to use
>> a pre-calculated table and a binary variable y to replace it. That
>> means the table is z --> log(z+1). If (x=z) then (y=1), else (y=0). I
>> do not know how to use inequal equations to express "If (x=z) then
>> (y=1), else (y=0)."
>> Who can help me? Thanks a lot!!!!
>
> Well if x and z are floating point (real) numbers then you *do not*
> want to compare them using .EQ. (OR ==).
>
> Let eps be a real constant set to some small tolerance.
>
> if abs(z-x)<eps then
> y=1
> else
> y=0
> end if

or, in Fortran,

if (abs(z-x)<epsilon(x)) then


y=1
else
y=0
end if

Regards,

Mike Metcalf

0 new messages