Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5880 > unrolled thread
| Started by | Meaghan <freecaptive6914@gmail.com> |
|---|---|
| First post | 2011-10-26 21:43 +0000 |
| Last post | 2011-10-27 10:47 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Overdetermined Matrix Equation Subject to Constraints Meaghan <freecaptive6914@gmail.com> - 2011-10-26 21:43 +0000
Re: Overdetermined Matrix Equation Subject to Constraints Ray Koopman <koopman@sfu.ca> - 2011-10-27 10:47 +0000
| From | Meaghan <freecaptive6914@gmail.com> |
|---|---|
| Date | 2011-10-26 21:43 +0000 |
| Subject | Overdetermined Matrix Equation Subject to Constraints |
| Message-ID | <j89uud$75$1@smc.vnet.net> |
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]];
[toc] | [next] | [standalone]
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2011-10-27 10:47 +0000 |
| Message-ID | <j8bcri$8v0$1@smc.vnet.net> |
| In reply to | #5880 |
On Oct 26, 2:43 pm, Meaghan <freecaptive6...@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}}
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web