MathGroup Archive 2008

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

Search the Archive

Re: Solving equations and inequalities with Reduce - how?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87697] Re: Solving equations and inequalities with Reduce - how?
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Tue, 15 Apr 2008 06:51:30 -0400 (EDT)
  • Organization: University of Bergen
  • References: <fu1tuf$ogc$1@smc.vnet.net>

Marc Heusser wrote:
> I tried to solve equations with Reduce and somehow did not quite 
> formulate it right, so Reduce complains with 
> "Reduce::ivar: 1 is not a valid variable".
>

One of the variables that you used in the equation already had a value. 
  Try it again in a fresh kernel.

> This is what I tried:
> 
> Wanted: A six digit number satisfying the following conditions:
> The first digit is not zero.
> If you take the first two digits and move them to the end of the number, 
> the resulting number must be twice the original number.
> 
> In[23]:=Reduce[200000a +20000 b +2000 c+200 d+20 e  +       2 f 
> \[Equal]100000c +10000 d +1000 e+100 f+10 a  + b ,  {a,b,c,d,e,f}, 
> Modulus\[Rule]9]

Here Modulus does not do what you expect (restrict the digits to 0..9).

But here's a way to solve the problem with Reduce:

We need to tell reduce that all of a, b, ..., f are integer digits, i.e. 
0 <= ... < 10, and also that a is not 0:

In[1]:= Reduce[
  a != 0 &&
   200000 a + 20000 b + 2000 c + 200 d + 20 e + 2 f ==
    100000 c + 10000 d + 1000 e + 100 f + 10 a + b &&
   And @@ Thread[0 <= {a, b, c, d, e, f} < 10],
  {a, b, c, d, e, f}, Integers]

Out[1]= (a == 1 && b == 4 && c == 2 && d == 8 && e == 5 &&
    f == 7) || (a == 2 && b == 8 && c == 5 && d == 7 && e == 1 &&
    f == 4) || (a == 4 && b == 2 && c == 8 && d == 5 && e == 7 &&
    f == 1)

In[2]:= {ToRules[%]}

Out[2]= {{a -> 1, b -> 4, c -> 2, d -> 8, e -> 5, f -> 7}, {a -> 2,
   b -> 8, c -> 5, d -> 7, e -> 1, f -> 4}, {a -> 4, b -> 2, c -> 8,
   d -> 5, e -> 7, f -> 1}}

In[3]:= FromDigits[{a, b, c, d, e, f}] /. %
Out[3]= {142857, 285714, 428571}



  • Prev by Date: Re: Numerical integration and list of points
  • Next by Date: Re: Re: List concatenation speed
  • Previous by thread: Re: Solving equations and inequalities with Reduce - how?
  • Next by thread: Re: Solving equations and inequalities with Reduce - how?