       Baffling Failure when plotting multiple curves.

• To: mathgroup at smc.vnet.net
• Subject: [mg44137] Baffling Failure when plotting multiple curves.
• From: Bob Harris <nitlion at mindspring.com>
• Date: Fri, 24 Oct 2003 04:24:06 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Howdy,

Am having trouble getting collections of 2D function plots to work.  I have
created a function that returns a list of "equations" in one variable,
theta.  I.e. an equation is an expression like 17 Cos[theta] + 10
Sin[theta].  When I try to plot this list of functions AS THE RETURN VALUE
OF MY FUNCTION, Mathematica complains (details below).  However, if I
evaluate the function first, then cut and paste the result into the call to
Plot, it works ok (but this is not very useful to me, since I want to
incorporate this into a larger function).  Further, if my function returns a
list with only one equation in it, then handing the function call to Plot
works.  I'm clueless as to what he difference is.

Here are the details.

This function returns a list of eqations, given a list of 2D points (cos[]
and sin[] are degree-based versions of Cos[] and Sin[] that I've defined)

voteCurves[pnts_List] := Module[{vc, xx, yy},
vc = {};
For[ix = 1, ix ¾ Length[pnts], ix++,
xx = pnts[[ix]][];
yy = pnts[[ix]][];
vc = Append[vc, xx cos[\[Theta]] + yy sin[\[Theta]]];
];

vc
]

Here are two typical points:

p1 = {158, 116};
p2 = {74 , 135};

and here's a typical list of equations result:

voteCurves[{p1, p2}]

{ 158 Cos[\[Pi] \[Theta] /180] + 116 Sin[\[Pi] \[Theta] /180],
74 Cos[\[Pi] \[Theta] /180] + 135 Sin[\[Pi] \[Theta] /180]}

This works (two equations, by cut and paste):

Plot[
{ 158 Cos[\[Pi] \[Theta] /180] + 116 Sin[\[Pi] \[Theta] /180],
74 Cos[\[Pi] \[Theta] /180] + 135 Sin[\[Pi] \[Theta] /180]},
{\[Theta], -90, 180},
AxesOrigin -> {0,0},
PlotRange -> {{-90, 180}, {0, 255 Sqrt}},
AspectRatio -> 1,
Frame -> True])

And this works (one equation, as function return value):

Plot[voteCurves[{p1}],{\[Theta], -90, 180},
AxesOrigin -> {0,0},
PlotRange -> {{-90, 180}, {0, 255 Sqrt}},
AspectRatio -> 1,
Frame -> True])

But this fails (two equations, as function return value):

Plot[voteCurves[{p1,p2}],{\[Theta], -90, 180},
AxesOrigin -> {0,0},
PlotRange -> {{-90, 180}, {0, 255 Sqrt}},
AspectRatio -> 1,
Frame -> True])

The errors I get are
Plot::"plnr": "\!\(voteCurves[\(\({p1, p2}\)\)]\) is not
a machine-size real number at \!\(\[Theta]\) = \!\(-89.99998875`\)."

My best guess is that the theta I return from my function call is considered
to be a different theta than the one I use in the plot statement.  But if
that is true, why does the function call usage work ok when the function
just returns one value?  I'm baffled trying to figure out the difference,
and in trying to come up with a solution.

Thanks for any help,
Bob Harris

P.S. I'm using Mathematica 4.0.1.0 on Mac OS 9.04 at home, *AND* Mathematica
5.something on Mac OSX at school.  Had the same problem on both.

```

• Prev by Date: Re: NDSolve does not work in shooting method
• Next by Date: Re: Why is this replacement not performed the first time?
• Previous by thread: Re: errors while picking random numbers under constraint and in loop also
• Next by thread: Re: Baffling Failure when plotting multiple curves.