MathGroup Archive 2011

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

Search the Archive

Re: Implicit Plot with parameter

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118908] Re: Implicit Plot with parameter
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Sun, 15 May 2011 07:05:11 -0400 (EDT)


----- Original Message -----
> From: "DrMajorBob" <btreat1 at austin.rr.com>
> To: mathgroup at smc.vnet.net
> Sent: Saturday, May 14, 2011 2:06:11 AM
> Subject: [mg118875] Re: Implicit Plot with parameter
> There are BIG timing differences when using Set or SetDelayed for h:
> 
> Clear[f, g, x, y, z]
> f[x_, y_, z_] = Sin[x*y/5 + z];
> g[x_, y_, z_] = Cos[y*z/5 + x + y^2];
> h[z_?NumericQ] :=
> y /. Quiet@Solve[{f[x, y, z] == 0, g[x, y, z] == 0}, {x, y}];
> 
> Timing@Plot[h[z], {z, -2, 2}, PlotPoints -> 10, MaxRecursion -> 1]
> 
> {71.4943, (* omitted *) }
> 
> h[z_?NumericQ] =
> y /. Quiet@Solve[{f[x, y, z] == 0, g[x, y, z] == 0}, {x, y}];
> Timing@Plot[h[z], {z, -2, 2}, PlotPoints -> 10, MaxRecursion -> 1]
> 
> {0.106993, (* omitted *) }
> 
> There's also this version, with Set but no test for NumericQ.
> 
> Clear[h]
> h[z_] = y /. Quiet@Solve[{f[x, y, z] == 0, g[x, y, z] == 0}, {x, y}];
> Timing@Plot[h[z], {z, -2, 2}, PlotPoints -> 10, MaxRecursion -> 1]
> 
> {1.90836, (* omitted *) }
> 
> The last two plots look the same, both very different from the first.
> 
> But wait, here's a THIRD version of the plot:
> 
> Clear[h]
> h[z_] = y /. Quiet@Solve[{f[x, y, z] == 0, g[x, y, z] == 0}, {x, y}];
> Timing@Plot[h[z] // Evaluate, {z, -2, 2}, PlotPoints -> 10,
> MaxRecursion -> 1, PlotStyle -> {Red, Black, Blue}]
> 
> {0.199036,(* omitted *)}
> 
> Plot #4 has more curve branches than #2 and #3, but fewer than #1.
> 
> Bobby
> [...]

I had not considered using Set, but you are correct that it makes sense here. The other issues are that it is easy to get spurious imaginary parts, and also that I had made Plot settings for speed and they mess up accuracy.

With all that in mind, the variant below should give a fast rendering with good fidelity.

h3[z_] = y /. Quiet@Solve[{f[x, y, z] == 0, g[x, y, z] == 0}, {x, y}];
Timing@Plot[Chop[h3[z]] // Evaluate, {z, -2, 2}, 
  PlotStyle -> {Red, Black, Blue}]

Daniel Lichtblau
Wolfram Research


  • Prev by Date: Re: Summation of imported data
  • Next by Date: Re: Seeing a solution of a differential equation as it run, using EvaluationMonitor
  • Previous by thread: Re: Implicit Plot with parameter
  • Next by thread: Histogram omits data points