Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Overdetermined Matrix Equation Subject to Constraints

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122410] Re: Overdetermined Matrix Equation Subject to Constraints
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Thu, 27 Oct 2011 06:34:24 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j89uud$75$1@smc.vnet.net>

On Oct 26, 2:43 pm, Meaghan <freecaptive6... at gmail.com> wrote:
> Hi all,
>
> I have an overdetermined matrix equation that I have been solving with
> LeastSquares[].  However, LeastSquares[] gives me solutions that don't
> fit my constraints (that all components of x >= 0).
> I know that Minimize[] and NMinimize[] minimize equations subject to
> constraints, but I cannot determine if they will minimize a *matrix*
> equation.
> Any ideas?
>
> Here is some sample code:
>
> referenceData = {{1.022299535`, 1.01884186`}, {0.15627907`,
>     0.716793488`}, {0.014162791`, 0.087627628`}};
> testData = {0.546942055`, -0.126062557`, -0.338173002`};
> Print["LeastSquares soln: ", LeastSquares[referenceData, testData]];
>
> unknown = {x, y};
> Print["Minimize soln: ",
>   Minimize[{referenceData.unknown - testData,
>     unknown[[1]] >= 0 && unknown[[2]] >= 0}, unknown]];

You need to minimize the sum of squares:

Clear[x,y]; unknown = {x, y};
Minimize[{#.#&[referenceData.unknown - testData],
          unknown[[1]] >= 0 && unknown[[2]] >= 0}, unknown] //Chop

{0.16218, {x->0.499802, y->0}}

This does the same thing but is more general:

Clear[x]; unknown = Array[x, Length@First@referenceData];
Minimize[{#.#&[referenceData.unknown - testData],
          Thread[unknown >= 0]}, unknown] //Chop

{0.16218, {x[1] -> 0.499802, x[2] -> 0}}



  • Prev by Date: Re: Using values from inside a matrix for a new row
  • Next by Date: Re: Using values from inside a matrix for a new row
  • Previous by thread: Re: Overdetermined Matrix Equation Subject to Constraints
  • Next by thread: Using values from inside a matrix for a new row