Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Solve / NSolve

  • To: mathgroup at smc.vnet.net
  • Subject: [mg95213] Re: [mg95191] Solve / NSolve
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Sun, 11 Jan 2009 06:35:52 -0500 (EST)
  • References: <200901091124.GAA17404@smc.vnet.net>
  • Reply-to: drmajorbob at longhorns.com

The code below can't succeed at all, as posted, since derData is undefined  
in the huygTemp function.

Without the missing pieces, we're not likely to reproduce your problem.

Bobby

On Fri, 09 Jan 2009 05:24:28 -0600, SigmundV <sigmundv at gmail.com> wrote:

> Dear group,
>
> Well, as the subject tells you I have an issue with Solve / NSolve.
> Instead of describing more in words I will ask you to evaluate the
> cells below. The plot you see there is what I expect to get; it is
> also correct. Now change NSolve to Solve in the line huygTemp. Don't
> you see a different plot now? Also the solution takes less time to
> compute, right? Could anyone explain to me this behaviour? Or at least
> try to explain it? Why does NSolve take so much more time to find a
> solution? And why is Solve finding the wrong one? Any suggestions on
> how to improve the huygTemp function (speedwise) are also welcome.
> Perhaps I should say that I'm using the following version of
> Mathematica: "6.0 for Sun Solaris SPARC (64-bit) (April 20, 2007)".
>
> Thank you in advance,
> Sigmund
>
>
> huygTemp = Function[{a, b, c, t0, t, r0, dphi},
>    Module[{x0 = r0[[1]], y0 = r0[[2]], x1, y1, dx0, dy0, eq1, eq2,
>      sol, pos, drop, x2, y2},
>     dx0 = derData[x0, dphi]; dy0 = derData[y0, dphi];
>     x0 = Delete[x0, {{1}, {-1}}]; y0 = Delete[y0, {{1}, {-1}}];
>     eq1 = Equal[#, 1] & /@ ((x - x0)^2/(a t)^2 + (y - y0 - c t)^2/(b t)
> ^2);
>     eq2 = Equal[#, 0] & /@ (-2 dx0 (x - x0)/(a t)^2 - 2 dy0 (y - y0 -
> c t)/(b t)^2);
>     sol = NSolve[#, {x, y}] & /@ (Transpose[{eq1, eq2}]);
>     x1 = x /. sol;
>     drop = Flatten@Position[Flatten[Differences /@ x1], x_ /; x == 0];
>     y1 = y /. sol;
>     pos = Ordering[Abs[#], -1] & /@ x1;
>     x2 = MapThread[Extract, {x1, pos}];
>     y2 = MapThread[Extract, {y1, pos}];
>     If[
>      drop != {},
>      y2[[drop]] = MapThread[Extract, {y1[[drop]], Ordering[Abs[#], -1]
> & /@ (Transpose@y1[[drop]])}]
>      ];
>     {x2, y2} = Join[{#[[-2]]}, #, {#[[2]]}] & /@ {x2, y2}
>     ]
>    ];
>
> Module[{a = 1, b = 2, c = 1, t0 = 1/100, t = 1/10, r0, phi,
>   dphi = 2 \[Pi]/50, front, fun, x1, y1, drop, pos, x2, y2},
>  phi = N@Range[-dphi, 2 \[Pi] + dphi, dphi];
>  r0 = {a t0 Cos[phi], b t0 Sin[phi] + c t0};
>  fun = huygTemp[a, b, c, t0, t, #, dphi] &;
>  front = Nest[fun, r0, 10] // Timing;
>  {First@front, ListPlot[Transpose@Last@front]}
>  ]
>



-- 
DrMajorBob at longhorns.com


  • Prev by Date: Re: Combining Plots with Different Ordinate Axes in Mathematica
  • Next by Date: About solution of complex system of DEs - to administrator -this is
  • Previous by thread: Re: Re: Plot in Background of Manipulate
  • Next by thread: Re: Re: Solve / NSolve