MathGroup Archive 2002

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

Search the Archive

RE: RE: how to extract parameter values

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37348] RE: [mg37316] RE: [mg37310] how to extract parameter values
  • From: "DrBob" <drbob at bigfoot.com>
  • Date: Thu, 24 Oct 2002 02:56:15 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Here's a method that's not blindingly fast, but still interesting:

a = {0.5, 0.25, 0.3};   b = {0.125, 0.35, 0.03}; 
{tmin, tmax} = {0, 2*Pi}; 
f[t_] := a . {Sin[t], Sin[2*t],      Sin[3*t]}; 
g[t_] := b . {Cos[t], Cos[2*t],     Cos[3*t]}
h[t_, {x_, y_}] = (f[t] - x)^2 +     (g[t] - y)^2; 
j[t_, {x_, y_}] = Simplify[    D[h[t, {x, y}], t]]; 
i[t_, {x_, y_}] := guess=2*t - guess /. FindRoot[h[t,{x, y}], {t,
guess},Jacobian -> {{j[t, {x, y}]}}]
Timing[plot = ParametricPlot[{f[t], g[t]}, {t, tmin, tmax}]; 
   list = Cases[plot, {x_, y_}, Infinity]; guess = tmin; 
   tvals = (i[t, #1] & ) /@ list; ]
ListPlot[tvals]

{0.281 Second, Null}

This is slightly faster, though probably not worth the extra effort:

nextGuess := guess.{1, -3, 3} (* quadratic extrapolation from previous
guesses *)
i[t_, {x_, y_}] := (guess = Join[Rest@guess, {t}] /. 
      FindRoot[h[t, {x, y}], {t, nextGuess}, Jacobian -> {{j[t, {x,
y}]}}])
Timing[plot = ParametricPlot[{f[t], g[t]}, {t, tmin, tmax}];
  list = Cases[plot, {x_, y_}, Infinity];
  guess = tmin{1, 1, 1};
  tvals2 = Last@i[t, #] & /@ list;
  ]

{0.266 Second, Null}

DrBob

-----Original Message-----
From: Wolf, Hartmut [mailto:Hartmut.Wolf at t-systems.com] 
To: mathgroup at smc.vnet.net
Subject: [mg37348] [mg37316] RE: [mg37310] how to extract parameter values




>-----Original Message-----
>From: Jan Mangaldan [mailto:jajem at yahoo.com]
To: mathgroup at smc.vnet.net
>Sent: Tuesday, October 22, 2002 10:49 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg37348] [mg37316] [mg37310] how to extract parameter values
>
>
>I'd like to know how I can extract the parameter
>values used by ParametricPlot in plotting a curve,
>e.g. if ParametricPlot used points corresponding to
>parameter values 2, 4, 6, etc... I need a way to get
>the list {2, 4, 6, ...}.
>
>One solution I know is this:
>
>list={};
>ParametricPlot[(AppendTo[list,t]; {f[t]
>g[t]}),{t,tmin,tmax}];
>
>The problem with this is that I get an error that
>ParametricPlot cannot compile the function, and that
>the plotting time is considerably slowed down.
>especially if I have a high PlotPoints setting.
>
>Any ideas?
>
>                                   Jan Mangaldan (~_~)

Jan,

please observe:

In[1]:= a = {0.5, 0.25, 0.3}; b = {0.125, 0.35, 0.03}; 
In[2]:=
f[t_] := a . {Sin[t], Sin[2*t], Sin[3*t]}; 
g[t_] := b . {Cos[t], Cos[2*t], Cos[3*t]}

In[4]:= {tmin, tmax} = {0, 2*Pi}; 
In[5]:= 
list = {}; s = {f[t], g[t]}; 
Timing[ParametricPlot[list = {list, t}; s, 
   {t, tmin, tmax}]]

ParametricPlot::"ppcom": "Function \!\(\(\(list = \(\({list, t}\)\)\)\)
;
s\) \
cannot be compiled; plotting will proceed with the uncompiled function."
Out[6]= {0.231 Second, - Graphics -}

In[7]:= tt = Flatten[list]; 
        Length[tt]
        ss = -Apply[Subtract, Partition[tt, 2, 1], {1}]; 
Out[8]= 271

In[10]:= ListPlot[tt]
In[11]:= ListPlot[ss, PlotJoined -> True, PlotRange -> All]

In[12]:= Timing[ParametricPlot[{f[t], g[t]}, {t, tmin, tmax}]]
Out[12]= {0.25 Second, - Graphics -}

You see the uncompiled version, including registering of the t-samples
is
faster than the "compiled version"?

In[13]:=
Timing[ParametricPlot[Evaluate[{f[t], g[t]}], {t, tmin, tmax}]]
Out[13]= {0.04 Second, - Graphics -}

In[14]:=
list = {}; s = Compile[t,{f[t], g[t]}]; 
Timing[ParametricPlot[list = {list, t}; s[t], 
   {t, tmin, tmax}];]
Out[15]= {0.32 Second, Null}

In[16]:=
list = {}; s = Compile[t,Evaluate[{f[t], g[t]}]]; 
Timing[ParametricPlot[list = {list, t}; s[t], 
   {t, tmin, tmax}];]
Out[17]= {0.1 Second, Null}

--
Hartmut Wolf






  • Prev by Date: Re: Poincare sections
  • Next by Date: Re: PlotVectorField3D in Cylindrical Coordinates
  • Previous by thread: RE: how to extract parameter values
  • Next by thread: RE: RE: how to extract parameter values