Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Trouble with a system of equations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77519] Re: [mg77488] Trouble with a system of equations
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Mon, 11 Jun 2007 04:27:33 -0400 (EDT)
  • References: <13301479.1181524668855.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

> eqns = {a + b + c + d == 4*m0, b + d == 4*m1, c + d == 4=
*m2, d ==
> 4*m3} /. {a -> t0/(1 + t0), b -> (t0*t1)/(1 + t0*t1), c -> (t0*t2)/(1
> + t0*t2), d -> (t0*t1*t2*t3)/(1 + t0*t1*t2*t3)}

Here's another way of stating the same definition:

eq = {a + b + c + d == 4*m0, b + d == 4*m1, c + d == 4*m2,
    d == 4*m3};
rules = {a -> t0/(1 + t0), b -> (t0 t1)/(1 + t0 t1),
    c -> (t0 t2)/(1 + t0 t2), d -> (t0 t1 t2 t3)/(1 + t0 t1 t2 t3)};
eqns = eq /. rules

{t0/(1 + t0) + (t0 t1)/(1 + t0 t1) + (t0 t2)/(1 + t0 t2) + (
    t0 t1 t2 t3)/(1 + t0 t1 t2 t3) ==
   4 m0, (t0 t1)/(1 + t0 t1) + (t0 t1 t2 t3)/(1 + t0 t1 t2 t3) ==
   4 m1, (t0 t2)/(1 + t0 t2) + (t0 t1 t2 t3)/(1 + t0 t1 t2 t3) ==
   4 m2, (t0 t1 t2 t3)/(1 + t0 t1 t2 t3) == 4 m3}

The result is something Solve can't solve for the t variables (for  
whatever reason). But you didn't have to complicate things that way.  
Instead, you can solve the problems separately:

s1 = Solve[eq, {a, b, c, d}]

{{a -> 4 (m0 - m1 - m2 + m3), b -> 4 (m1 - m3), c -> 4 (m2 - m3),
   d -> 4 m3}}

s2 = Solve[rules /. Rule -> Equal, {t0, t1, t2, t3}]

{{t3 -> (a (1 - b - c + b c) d)/((-1 + a) b c (-1 + d)),
   t1 -> (-b + a b)/(a (-1 + b)), t2 -> ((-1 + a) c)/(a (-1 + c)),
   t0 -> -a/(-1 + a)}}

and combine the two solutions:

s2[[1]] /. s1

{{t3 -> ((1 - 4 (m1 - m3) - 4 (m2 - m3) +
       16 (m1 - m3) (m2 - m3)) m3 (m0 - m1 - m2 + m3))/((m1 - m3) (m2 -
        m3) (-1 + 4 m3) (-1 + 4 (m0 - m1 - m2 + m3))),
   t1 -> (-4 (m1 - m3) + 16 (m1 - m3) (m0 - m1 - m2 + m3))/(
    4 (-1 + 4 (m1 - m3)) (m0 - m1 - m2 + m3)),
   t2 -> ((m2 - m3) (-1 + 4 (m0 - m1 - m2 + m3)))/((-1 +
       4 (m2 - m3)) (m0 - m1 - m2 + m3)),
   t0 -> -(4 (m0 - m1 - m2 + m3))/(-1 + 4 (m0 - m1 - m2 + m3))}}

eqns /. % // Simplify

{{True, True, True, True}}

Always take advantage of what you know about the problem structure.

Bobby

On Sun, 10 Jun 2007 06:20:40 -0500, Yaroslav Bulatov  
<yaroslavvb at gmail.com> wrote:

> Hi, I'm trying to solve a certain kind of system of equations, and
> while they are solvable by hand, Mathematica 6.0 has problems solving
> it
>
> Here's an example
>
> eqns = {a + b + c + d == 4*m0, b + d == 4*m1, c + d == 4*m2, d ==
> 4*m3} /. {a -> t0/(1 + t0), b -> (t0*t1)/(1 + t0*t1), c -> (t0*t2)/(1
> + t0*t2), d -> (t0*t1*t2*t3)/(1 + t0*t1*t2*t3)}
> Solve[eqns, {t0, t1, t2, t3}]
>
> The solution can be found by hand and verified below
>
> sol = {t0 -> a/(1/4 - a), t1 -> (b/(1/4 - b))*((1/4 - a)/a), t2 -> (c/
> (1/4 - c))*((1/4 - a)/a), t3 -> (m3/(1/4 - m3))*(a/(1/4 - a))*((1/4 -
> b)/b)*((1/4 - c)/c)} /. {a -> m0 - m1 - m2 + m3, b -> m1 - m3, c -> m2
> - m3}
> eqns /. sol // Simplify
>
> This is an example of estimating equations for a saturated logistic
> regression model with 2 independent variables. I'd like to see if
> formulas also exist for more variables, but they are too cumbersome to
> solve by hand. Are there any Mathematica tricks I can use to answer
> this question?
>
> Here's the procedure that generates the system of equations for d
> variables (d=2 produces the system above)
>
> logeq[d_] := Module[{bounds, monomials, params,
> partition,derivs,sums},
>    xs = (Subscript[x, #1] & ) /@ Table[i, {i, 1, d}];
>     monomials = Subsets[xs]; monomials = (Prepend[#1, 1] & ) /@
> monomials;
>     monomials = (Times @@ #1 & ) /@ monomials;
>     params = (Subscript[th, #1] & ) /@ Table[i, {i, 0, 2^d - 1}];
>     monomials = (Times @@ #1 & ) /@ Thread[{params, monomials}];
>     partition = Log[1 + Exp[Plus @@ monomials]];
>     derivs = (D[partition, Subscript[th, #1]] & ) /@
>       Table[i, {i, 0, 2^d - 1}]; bounds = ({#1, 0, 1} & ) /@ xs;
>     sums = (Table[#1, Evaluate[Sequence @@ bounds]] & ) /@ derivs;
>     sums = (Plus @@ #1 & ) /@ (Flatten[#1] & ) /@ sums;
>     Thread[sums == Table[Subscript[m, i], {i, 0, 2^d - 1}]]]
>
>
>



-- 
DrMajorBob at bigfoot.com


  • Prev by Date: Re: Trouble with a system of equations
  • Next by Date: Re: Trouble with a system of equations
  • Previous by thread: Re: Trouble with a system of equations
  • Next by thread: Re: Re: Trouble with a system of equations