MathGroup Archive 2011

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

Search the Archive

Re: Implicit Plot with parameter

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118875] Re: Implicit Plot with parameter
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Sat, 14 May 2011 03:06:11 -0400 (EDT)

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

On Fri, 13 May 2011 05:24:14 -0500, Daniel Lichtblau <danl at wolfram.com>  
wrote:

> victorphy wrote:
>> Hi,
>>
>> I have a system of two implicit equations, say f[x,y,z] =0 &&
>> g[x,y,z] =0 (think of z as a parameter) and I would like to plot the
>> solutions as 'y as a function of z'; that is, I don't car about the
>> value that x takes for a given z.
>>
>>
>> Is there a way to do it with Mathematica ? I tried using ContourPlot
>> but I couldn't find the way.
>>
>> Any help would be very appreciated.
>>
>>
>> Best Regards
>>
>> Victor
>
> Depends on the functions. If they are amenable to using Solve, could do
> as below.
>
> 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}]]
>
> Plot[h[z], {z, -2, 2}, PlotPoints -> 10, MaxRecursion -> 1]
>
> Another possibility might be to minimize a sum of squares given values
> for y and z, and then attempt a contour plot of that minimizing function.
>
> h2[y_?NumericQ, z_?NumericQ] :=
>   First[FindMinimum[f[x, y, z]^2 + g[x, y, z]^2, {x, -1, 1}]]
>
> ContourPlot[h2[y, z], {y, -2, 2}, {z, -2, 2}, ContourShading -> False,
>    Contours -> {.0001}, PlotPoints -> 80]
>
> Daniel Lichtblau
> Wolfram Research
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: ContourPlot with variable functions as input
  • Next by Date: Re: Rotating a surface similar to a helix
  • Previous by thread: Re: Implicit Plot with parameter
  • Next by thread: Re: Implicit Plot with parameter