Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: what is my error?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg100477] Re: [mg100438] what is my error?
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Fri, 5 Jun 2009 03:02:16 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

There are multiple solutions

eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}

{mp + mr == 13, fp + fr == 19, fr + mr == 15, fp + mp == 17}

soln[fp_] = Quiet[Solve[eqns, {mr, mp, fr, fp}][[1]]]

{mr -> fp - 4, mp -> 17 - fp, fr -> 19 - fp}

solns1 = Table[Join[{fp -> fpi}, soln[fpi]], {fpi, 5, 16}]

{{fp -> 5, mr -> 1, mp -> 12, fr -> 14}, {fp -> 6, mr -> 2, mp -> 11, 
     fr -> 13}, {fp -> 7, mr -> 3, mp -> 10, fr -> 12}, 
   {fp -> 8, mr -> 4, mp -> 9, fr -> 11}, {fp -> 9, mr -> 5, mp -> 8, 
     fr -> 10}, {fp -> 10, mr -> 6, mp -> 7, fr -> 9}, 
   {fp -> 11, mr -> 7, mp -> 6, fr -> 8}, {fp -> 12, mr -> 8, mp -> 5, 
     fr -> 7}, {fp -> 13, mr -> 9, mp -> 4, fr -> 6}, 
   {fp -> 14, mr -> 10, mp -> 3, fr -> 5}, {fp -> 15, mr -> 11, mp -> 2, 
     fr -> 4}, {fp -> 16, mr -> 12, mp -> 1, fr -> 3}}

And @@ (eqns /. solns1 // Flatten)

True

Reduce[Join[eqns, Thread[{mr, mp, fr, fp} > 0]], {mr, mp, fr, fp}]

0 < mr < 13 && mp == 13 - mr && fr == 15 - mr && fp == 19 - fr

Restricting the domain to Integers

solns2 = {Reduce[Join[eqns, Thread[{mr, mp, fr, fp} > 0]], {mr, mp, fr, fp}, 
    Integers] // ToRules}

{{mr -> 1, mp -> 12, fr -> 14, fp -> 5}, {mr -> 2, mp -> 11, fr -> 13, 
     fp -> 6}, {mr -> 3, mp -> 10, fr -> 12, fp -> 7}, 
   {mr -> 4, mp -> 9, fr -> 11, fp -> 8}, {mr -> 5, mp -> 8, fr -> 10, 
     fp -> 9}, {mr -> 6, mp -> 7, fr -> 9, fp -> 10}, 
   {mr -> 7, mp -> 6, fr -> 8, fp -> 11}, {mr -> 8, mp -> 5, fr -> 7, 
     fp -> 12}, {mr -> 9, mp -> 4, fr -> 6, fp -> 13}, 
   {mr -> 10, mp -> 3, fr -> 5, fp -> 14}, {mr -> 11, mp -> 2, fr -> 4, 
     fp -> 15}, {mr -> 12, mp -> 1, fr -> 3, fp -> 16}}

And @@ (eqns /. solns2 // Flatten)

True


Bob Hanlon

---- Richard Palmer <rhpalmer at gmail.com> wrote: 

=============
eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}NSolve[eqns,
{mr, mp, fr, fp}]

gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}}

The solution is  {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are greater
than zero

-- 
Richard Palmer



  • Prev by Date: Re: How to handle Units of Measure
  • Next by Date: Re: creating an array in a loop
  • Previous by thread: Re: what is my error?
  • Next by thread: Learning Trace more....