MathGroup Archive 2002

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

Search the Archive

Re: ListPlot with multiple (related) series.

  • To: mathgroup at
  • Subject: [mg33479] Re: [mg33420] ListPlot with multiple (related) series.
  • From: Daniel Lichtblau <danl at>
  • Date: Fri, 22 Mar 2002 04:07:29 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at

Curt Fischer wrote:
> Dear Group,
> equations as a function of a parameter of the equations b.  Problem
> is, there are multiple solution sets and my graph does not show which
> x goes with which y at a given b.  How can I make such a graph?
> Details:
> In my problem, I have three equations in three unknowns x, y, and z.
> b is a parameter in these equations.  Using NSolve, I built a function
> which takes b as a variable and returns the values of x, y, and z,
> like this;
> soln[b_]:=NSolve[{eqns},{x,y,z}]
> This is all good.  My equations are rational, and NSolve returns at
> most three solutions sets {x,y,z} for any given b.
> Now, I want to plot x and y vs. b, on the same graph.  I want the
> graph to show every solution set for each b.
> I tried:
> Show[{
>       ListPlot[
>         Flatten[
>           Table[Table[{i, x/.soln[i][[n]]]}, {i,1,10,.2}],{n, 1, 3}],
> 1],
>         PlotStyle -> {PointSize[ .02], RGBColor[1, 0, 0]},
>         DisplayFunction -> Identity],
>       ListPlot[
>         Flatten[
>           Table[Table[{i, y/.soln[i][[n]]]}, {i,1,10,.2}],{n, 1, 3}],
> 1],
>         PlotStyle -> {PointSize[ .02], RGBColor[0, 1, 0]},
>         DisplayFunction -> Identity]},
>     DisplayFunction -> $DisplayFunction]
> which worked and a output a graph. Problem is, since there are three
> solutions, there are three distinct red (x) and three distinct green
> (y) points for every b.  There is no way of knowing which x goes with
> which y from this graph.
> How can I make a graph which preserves this information?  It is not as
> important to me to keep to color difference in x and y as it is to
> distinguish solution 1 from solution 2 from solution 3...but is there
> an easy way to do both in the same graph?
> Thanks for your help.
> --
> Curt Fischer
> crf3 at

I'll show a basic example using two equations in two variables. There
are two approaches that come to mind. One is to pick at each "new" b
value, for a successor to a given solution at the previous value, the
one that is closest to that previous solution. This will work fine until
you get near b-values where solution paths cross.

An alternative is to solve for a given initial value of b, convert to a
system of ODEs with b as independent value, and give as separate initial
solutions the solutions for the initial b value. This is what is done
below. I think Carl Woll has posted variations of this in the past (but
if it does not work for your purposes you should probably blame me and
not him).

eqns = {1+3*x[b]-7*x[b]*y[b]+b*x[b]*y[b]^2-x[b]^2,

In[34]:= initsoln = NSolve[eqns /. b->3, {x[3],y[3]}]
Out[34]= {{x[3] -> -0.0428556, y[3] -> 4.01708}, 
  {x[3] -> 2.83817, y[3] -> 2.25741}, 
  {x[3] -> -0.074289, y[3] -> -1.02954}, 
  {x[3] -> 2.25857, y[3] -> 0.183619}}

odes = D[eqns /. {x->x[b],y->y[b]}, b]

sol1 = First[NDSolve[Join[Thread[odes==0],
	Thread[{x[3],y[3]} == ({x[3],y[3]}/.initsoln[[1]])]],
	{x[b], y[b]}, {b,3,6}]];

Now you can plot the solution over b in the range for which we solved:

ParametricPlot[Evaluate[{x[b], y[b]} /. sol1], {b,3,6}]

Similarly you can get plots for solutions using the other three initial
values, e.g.

sol2 = First[NDSolve[Join[Thread[odes==0],
	Thread[{x[3],y[3]} == ({x[3],y[3]}/.initsoln[[2]])]],
	{x[b], y[b]}, {b,3,6}]]

ParametricPlot[Evaluate[{x[b], y[b]} /. sol2], {b,3,6}]

One drawback to this approach is that you have to have some idea of how
far you can continue a solution, in the parameter b, without it becoming

Daniel Lichtblau
Wolfram Research

  • Prev by Date: Re: Adding columns and rows to a table
  • Next by Date: Integrate fails
  • Previous by thread: ListPlot with multiple (related) series.
  • Next by thread: RE: ListPlot with multiple (related) series.