On 2013-04-02, Thomas D. Dean <tomdean at speakeasy.org> wrote:
> On 04/01/13 16:00, Robert Dodier wrote:
>> for i:1 thru length(eq3) do if imagpart(rhs(eq3[i])) = 0 then plteq:eq4[i];
>
> eq3 is a list of the form [x=..., x=..., x=...] so
>
> imagpart(eq3[2]); /* for example, */
> returns 0 = 3*sqrt(7)/4
> and
> imagpart(eq3[3]);
> returns 0 = 0
Oh -- I get it now.
> I believe imagpart(x) is zero when x is not assigned. Is this always true?
Well, not necessarily -- if x is declared complex (i.e. declare(x,
complex)) then imagpart(x) => imagpart(x). However, that's not the case
in your example, so imagpart(x) => 0 indeed. My advice is, don't count
on imagpart(x) => 0, and write imagpart(rhs(eq3[i])) = 0 instead.
However, that won't change the outcome in your example.
Another minor quibble -- if there are multiple real solutions, the loop
assigns plteq to the last one. Maybe you should put the call to plot2d
into the loop, so if there are multiple solutions, it will plot all of
them? As above, that won't change the outcome in the example at hand.
best
Robert Dodier