MathGroup Archive 2006

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

Search the Archive

Re: Unexpected "Invalid comparison" error when plotting function defined with a Condition pattern

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69171] Re: Unexpected "Invalid comparison" error when plotting function defined with a Condition pattern
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 1 Sep 2006 06:40:16 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <ed68td$jgk$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Andrew Moylan wrote:
> Hi,
> 
> Please consider the following simple function, defined for positive x
> using a Condition pattern:
> 
>   g[x_ /; 0 < x] = x;
> 
> When I try to plot this function in the following way:
> 
>   Plot[Abs[g[10^y]], {y, 1, 2}];
> 
> I unexpectedly receive some "Less::nord : Invalid comparison with 10. +
> 0. I attempted" errors. Can anyone explain why this is, and how I
> should best prevent it?
> 
> Relevant note:
> Both of the following different plots of g succeed with no errors:
>   Plot[Abs[g[y]], {y, 1, 2}];
>   Plot[g[10^y], {y, 1, 2}];
> 
> Irrelevant note:
> In my actual application, the function g is more complicated and is
> complex-valued (hence my use of Abs); but the error is reproducable
> with the very simple real-valued function g as defined above.
> 
> Thanks for any insight you might be able to give me on this.
> 
> Cheers,
> 
> Andrew
> 
Hi Andrew,

Functions like Less cannot compare complex values: this is the meaning 
of the warning message you received.

Less::"nord" : "Invalid comparison with (\"10.0000009594105\" + 
\"0.*I\") attempted. More...

-->

. Generated when complex numbers occur in functions such as Min or 
Greater that make numerical comparisons of real numbers.
. This message is often generated indirectly by other functions that 
internally make comparisons of real numbers.

You can try

g[x_Real /; 0 < x] := x;
Plot[Abs[g[10^y]], {y, 1, 2}];

Regards,
Jean-Marc


  • Prev by Date: the ellipse and the circle
  • Next by Date: RE: Unexpected "Invalid comparison" error when plotting function defined with a Condition pattern
  • Previous by thread: Re: Unexpected "Invalid comparison" error when plotting function defined with a Condition pattern
  • Next by thread: RE: Unexpected "Invalid comparison" error when plotting function defined with a Condition pattern