MathGroup Archive 1999

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

Search the Archive

Re: NSolve with varying parameter

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18719] Re: [mg18692] NSolve with varying parameter
  • From: Carl Woll <carlw at u.washington.edu>
  • Date: Sat, 17 Jul 1999 02:36:40 -0400
  • Organization: Physics Department, U of Washington
  • References: <199907150546.BAA15972@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

Dan,

I think the simplest approach is to turn the problem into a differential
equation and use NDSolve. For example, suppose you are trying to solve the
equations

x^2 + y^2 == a^2
y == x^2

for the parameter a in the range 0 to 1, and the output you want is
interpolating functions for x and y as a function of a. Define

In[42]:=
f[a_, x_, y_] := x^2 + y^2 - a^2
g[a_, x_, y_] := y - x^2

Now, turn the problem into a differential equation. Do this by
differentiating f[a,x[a],y[a]] and g[a,x[a],y[a]] with respect to a, and by
supplying two initial conditions, say at a=1 (the choice a=0 doesn't work
here because multiple solutions intersect at this point). In fact, it's
easiest to let Mathematica do the above:

In[60]:=
NDSolve[{D[f[a,x[a],y[a]],a]==0,D[g[a,x[a],y[a]],a]==0,f[1,x[1],y[1]]==0,
    g[1,x[1],y[1]]==0},{x,y},{a,0,1}]

Out[60]=
{{x -> InterpolatingFunction[{{0., 1.}}, <>],

   y -> InterpolatingFunction[{{0., 1.}}, <>]},

  {x -> InterpolatingFunction[{{0., 1.}}, <>],

   y -> InterpolatingFunction[{{0., 1.}}, <>]},

  {x -> InterpolatingFunction[{{0., 1.}}, <>],

   y -> InterpolatingFunction[{{0., 1.}}, <>]},

  {x -> InterpolatingFunction[{{0., 1.}}, <>],

   y -> InterpolatingFunction[{{0., 1.}}, <>]}}

There are apparently four solutions to this particular problem, with the
first two being imaginary and the last two real. I've plotted both
f[a,x[a],y[a]] and g[a,x[a],y[a]] over the interval [0,1], and they are
indeed zero. So, the above method should produce the interpolating
functions you want, and in my opinion it's a pretty elegant method (said as
I'm hurting my arm patting myself on the back). Good luck, and let me know
if you have any problems.

Carl Woll
Physics Dept
U of Washington

Dr Dan wrote:

> I have encountered a problem that I think is general enough that there
> should be a built-in or standard package function, but I cannot find it.
>
> I have a set of algebraic equations in several variables (determined
> system; #equations = #variables) and a single parameter.  I need a
> function that will numerically solve the system over an interval of
> values for the parameter and return InterpolatingFunction's.  The
> syntax would be much like NDSolve, with the equations restricted to
> algebraic only.
>
> For simple systems, I can use Solve to get explicit functions in the
> parameter; but I cannot ensure that the equations in question will have
> a closed form solution.
>
> I have written my own function to do this using NSolve and
> NestWhileList, but I would certainly rather use a built-in if one
> exists.
>
> Any suggestions?
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.



--
Carl Woll
Dept of Physics
U of Washington



  • Prev by Date: Re: Is there a FAQ? (Clear all)
  • Next by Date: Re: [Q] Implementing identities as rules
  • Previous by thread: NSolve with varying parameter
  • Next by thread: Re: NSolve with varying parameter