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

MathGroup Archive 2007

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

Search the Archive

Re: solution to undetermined linear equation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83991] Re: [mg83942] solution to undetermined linear equation
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Thu, 6 Dec 2007 02:45:55 -0500 (EST)
  • References: <4895754.1196897174998.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

The constraint that "all the weights must be nonzero" makes the problem 
difficult; I'll ignore it for now.

Here's a setup for the problem (with randomly chosen coefficients):

gvec = Array[g, 13]

{g[1], g[2], g[3], g[4], g[5], g[6], g[7], g[8], g[9], g[10], g[11],
  g[12], g[13]}

m = RandomReal[{-1, 1}, {13, 3}];
obj1 = gvec.m;
obj2 = #.# &[obj1];

Minimize[{obj2, Total@gvec == 13}, gvec]

{1.1895*10^-31, {g[1] -> 5.77492, g[2] -> 0.588401, g[3] -> 0.860516,
   g[4] -> 0.750811, g[5] -> 0.108545, g[6] -> 1.22947,
   g[7] -> 0.876558, g[8] -> 0.590213, g[9] -> 0.53078,
   g[10] -> 1.03768, g[11] -> -0.418626, g[12] -> 0.471749,
   g[13] -> 0.598983}}

Here's a solution using Minimize:

Minimize[{obj2, Total@gvec == 13}, gvec]

{1.1895*10^-31, {g[1] -> 5.77492, g[2] -> 0.588401, g[3] -> 0.860516,
   g[4] -> 0.750811, g[5] -> 0.108545, g[6] -> 1.22947,
   g[7] -> 0.876558, g[8] -> 0.590213, g[9] -> 0.53078,
   g[10] -> 1.03768, g[11] -> -0.418626, g[12] -> 0.471749,
   g[13] -> 0.598983}}

And here's a linear algebra solution, with a check on the constraints:

soln1 = First@
   Quiet@Solve[Flatten@{Thread[obj1 == 0], Total@gvec == 13}, gvec]
{obj1, Total@gvec} /. soln1 // Simplify // Chop

{g[1] -> 4.34554- 1.86478 g[5] + 1.11788 g[6] + 1.39554 g[7] +
    0.609062 g[8] + 0.85836 g[9] - 1.18596 g[10] - 0.235194 g[11] +
    0.617057 g[12] - 1.56911 g[13],
  g[2] -> 3.24756- 0.782057 g[5] - 0.723537 g[6] - 0.71926 g[7] +
    0.558484 g[8] + 0.231554 g[9] - 1.3287 g[10] - 0.799617 g[11] +
    0.0856483 g[12] - 0.839982 g[13],
  g[3] -> 0.388265- 0.28712 g[5] + 0.694379 g[6] + 0.591973 g[7] -
    0.0669889 g[8] - 0.322397 g[9] + 0.222869 g[10] - 0.492421 g[11] -
    1.03194 g[12] - 1.01694 g[13],
  g[4] -> 5.01864+ 1.93395 g[5] - 2.08873 g[6] - 2.26825 g[7] -
    2.10056 g[8] - 1.76752 g[9] + 1.2918 g[10] + 0.527233 g[11] -
    0.670769 g[12] + 2.42603 g[13]}

{{0, 0, 0}, 13.}

Notice that's a 9-dimensional SPACE of solutions, not just one.

The constraint that "all the weights must be nonzero" makes linear algebra  
unusable if used directly, but one might try instead "all the weights must  
be POSITIVE", in which case Solve fails:

First@Solve[
    Flatten@{Thread[obj1 == 0], Total@gvec == 13, Thread[gvec > 0]},
    gvec];

Solve::eqf: g[13]>0 is not a well-formed equation. >>

But Minimize has no problem with it:

Minimize[Flatten@{obj2, Total@gvec == 13, Thread[gvec > 0]}, gvec]

{1.23455*10^-31, {g[1] -> 4.38325, g[2] -> 0.481395, g[3] -> 0.314046,
    g[4] -> 1.99654, g[5] -> 0.759683, g[6] -> 0.713266,
   g[7] -> 0.887778, g[8] -> 1.19497, g[9] -> 0.403486,
   g[10] -> 0.821527, g[11] -> 0.409302, g[12] -> 0.187768,
   g[13] -> 0.446988}}

I think technically this could have returned variables that ARE zero,  
since ">" must be treated like ">=" -- but that didn't happen. Anyway, the  
9-dimensional solution found earlier can easily be tweaked to find  
non-zero solutions.

You can try FindInstance directly, in fact:

FindInstance[
  Flatten@{Thread[obj1 == 0], Total@gvec == 13,
    Thread[gvec > 0]}, gvec]

{{g[1] -> 5.11765, g[2] -> 2.29094, g[3] -> 0.795716, g[4] -> 2.37257,
    g[5] -> 0.488027, g[6] -> 0.461637, g[7] -> 0.574777,
   g[8] -> 0.527069, g[9] -> 0.217686, g[10] -> 0.109726,
   g[11] -> 0.0246191, g[12] -> 0.0104144, g[13] -> 0.00916999}}

Bobby

On Wed, 05 Dec 2007 06:09:05 -0600, shama shahbaz  
<shammashahbaz at yahoo.com> wrote:

> hi
>  my basic problem is i have a matrix  13*3  of values
>  -0.2028            0.12778    -0.09129
>   0.1278             -0.09129    0.07089
>   -0.09129           0.07089     -0.05731
>   0.07089            -0.05731     0.04902
>   -0.05731             0.04902     -0.04188
>   0.04902             0.04188        0.03747
>  .............
>   ............
>  i want to find wieght factors which when applied to above values would  
> result in a value close to 0
>  such as
>  -0.2028  g1 +  0.1278  g2 +   -0.09129 g3 +0.07089 
> g4+........................g13=min
>    0.12778 g1+-0.09129g2 + 0.07089 g3  +    
> -0.05731g4+.........................g13=min
>    -0.09129g1+0.07089g2+   -0.05731g3  +    0.04902  
> g4+........................g13=min
>  howeverthe values of g's should be subjected to the constraint
>  g1+g2+g3+.........................g13=13 and all the wieghts must be  
> nonzero
>  Is it possible
>  thankyou for your patience
>   regards,
>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Exporting Sound
  • Next by Date: RE: Re: Re: Presentations Package Announcement
  • Previous by thread: Re: solution to undetermined linear equation
  • Next by thread: Re: File reading and writing within for loop