MathGroup Archive 2008

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

Search the Archive

Re: How to remove duplicate solutions (Solve)?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91797] Re: How to remove duplicate solutions (Solve)?
  • From: magma <maderri2 at gmail.com>
  • Date: Mon, 8 Sep 2008 05:02:44 -0400 (EDT)
  • References: <ga24hv$gia$1@smc.vnet.net>

On Sep 8, 5:01 am, Peng Yu <PengYu... at gmail.com> wrote:
> Hi,
>
> Solve[(x - 1)^2 == 0, x]
>
> The above code would give me the solution
> {{x -> 1}, {x -> 1}}
>
> But one is a duplicate of the other. I'm wondering how to only produce
> the unique solutions.
>
> Thanks,
> Peng

It is very simple.
Solve gives you a list, that is a collection of elements which may be
duplicates and have (and have a specific order, but that is not
important now).
You want to transform this into a set, that is a collection of
elements without duplicates.
Union does that, among other things.

So:

In[7]:= Solve[(x - 1)^2 == 0, x]

Out[7]= {{x -> 1}, {x -> 1}}

In[8]:= Union[%]

Out[8]= {{x -> 1}}



  • Prev by Date: Re: How to remove duplicate solutions (Solve)?
  • Next by Date: Re: Help on Collecting Integers
  • Previous by thread: Re: How to remove duplicate solutions (Solve)?
  • Next by thread: How to always output result in InputForm from the command line