RE: Unexpected "Invalid comparison" error when plotting function defined with a Condition pattern
- To: mathgroup at smc.vnet.net
- Subject: [mg69189] RE: [mg69165] Unexpected "Invalid comparison" error when plotting function defined with a Condition pattern
- From: "David Park" <djmp at earthlink.net>
- Date: Fri, 1 Sep 2006 06:41:30 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Andrew, I do not know precisely why you obtain those error messages. It seems to be a combination of selecting values in Plot, the use of Abs and the form of the definition of g. But I think there are ways around it. The following give error messages. g[x_ /; 0 < x] = x; Plot[Abs[g[10^y]], {y, 1, 2}]; Clear[g] g[x_ ] = If[x > 0, x, 0]; Plot[Abs[g[10^y]], {y, 1, 2}]; Clear[g] g[x_] := Piecewise[{{0, x <= 0}, {x, x > 0} }] Plot[Abs[g[10^y]], {y, 1, 2}]; The following do not give error messages. Clear[g] g[x_ /; 0 < x] = x; Plot[Sqrt[g[10^y]^2], {y, 1, 2}]; Clear[g] g[x_ /; 0 < x] = x; Plot[Abs[g[10^y]] // ComplexExpand // Evaluate, {y, 1, 2}]; Clear[g] g[x_ /; 0 < x] = x; data = Table[{y, Abs[g[10^y]]}, {y, 1, 2, 0.025}]; ListPlot[data, PlotJoined -> True]; Clear[g] g[x_?Positive] = x; Plot[Abs[g[10^y]], {y, 1, 2}]; Clear[g] g[x_] := Piecewise[{{0, x <= 0}, {x, x > 0} }] Plot[Abs[g[10^y]] // ComplexExpand // Evaluate, {y, 1, 2}]; So try using ComplexExpand on your more complicated expression. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Andrew Moylan [mailto:andrew.j.moylan at gmail.com] To: mathgroup at smc.vnet.net 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