MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Floor[] Not An Integer?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56590] Re: [mg56493] Floor[] Not An Integer?
  • From: DrBob <drbob at bigfoot.com>
  • Date: Fri, 29 Apr 2005 03:21:44 -0400 (EDT)
  • References: <A4628A7C27BF0D48847FD4AB8536731D73FFAC@blinky.mobile-mind.com>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

Mathematica doesn't complain about EITHER expression, at this machine (with version 5.1.1). It shouldn't in previous versions either, but maybe it does; I don't know.

5.1.1 does complain about this one, which is almost identical to the first:

Device[x_] = sigs[[Floor[x]]] + (x - Floor[x])(sigs[[Ceiling[
     x]]] - sigs[[Floor[x]]])

That's because the right-hand side is computed immediately, when x has no value, so Floor[x] can't be computed. That wouldn't be a problem in itself; it's Part that complains, because the index is not an integer.

This expression is OK, though:

Device[x_] = Which[x â?¤ 1,
   0, x â?¥ 255, 100, True, sigs[[Floor[x]]] + (x - Floor[x])(sigs[[Ceiling[
     x]]] - sigs[[Floor[x]]])]

That's because, as Help says:

"If any of the test_i evaluated by Which give neither True nor False, then a Which object containing these remaining elements is returned unevaluated."

The first test is inconclusive, so Which and the rest of its arguments remain unevaluated.

It might be better if Part had a similar behavior.

Bobby

On Thu, 28 Apr 2005 16:52:58 -0400, Scott Guthery <sguthery at mobile-mind.com> wrote:

> Mathematica grumps about Floor[x] not being an integer in this expression:
>
> Device[x_] := sigs[[Floor[x]]] + (x - Floor[x])(sigs[[Ceiling[
>     x]]] - sigs[[Floor[x]]])
>
> but it does NOT grump about Floor[x] not being an integer in this expression:
>
> Device[x_] := Which[x <= 1,
>   0, x â?¥ 255, 100, True, sigs[[Floor[x]]] + (x - Floor[x])(sigs[[Ceiling[
>     x]]] - sigs[[Floor[x]]])]
>
> Why should the Which[..] construct make a difference?
>
> Thanks for any insight.
>
> Cheers, Scott
>
> -----Original Message-----
> From: DrBob [mailto:drbob at bigfoot.com]
To: mathgroup at smc.vnet.net
> Sent: Tuesday, April 26, 2005 11:14 PM
> Subject: [mg56590] Re: [mg56493] Floor[] Not An Integer?
>
> Floor[x] is NOT an integer, unless x is a NUMBER.
>
> Bobby
>
> On Tue, 26 Apr 2005 21:53:01 -0400 (EDT), Scott Guthery <sguthery at mobile-mind.com> wrote:
>
>> I'm trying to use some of the NumericalMath approximations such as
>> MiniMaxApproximation and RationalInterpolation with a function that
>> includes array references of the form Array[[Floor[x]]].  The function
>> plots and evaluates just fine but the NumericalMath functions are
>> reporting the error:
>>
>> "Part::pspec: Part specification Floor[x] is neither an integer nor a
>> list of integers."
>>
>> whereas the documentation states that Floor[x] IS an integer.
>>
>> What am I missing?
>>
>> Thanks for any insight.
>>
>> Cheers, Scott
>>
>>
>>
>>
>
>
>



-- 
DrBob at bigfoot.com


  • Prev by Date: Re: can Mathematica be useful for this?
  • Next by Date: Re: Re: Using BarChart in a Widget
  • Previous by thread: Re: Floor[] Not An Integer?
  • Next by thread: front end error when making boxes