All possible A of Ax=b with constraints on A

Clash Royale CLAN TAG#URR8PPP
$begingroup$
I have a linear problem that I want to solve but the method is quite different from normal, the problem is still Ax=b. However,
in this instant I have A being unknown, apart from the fact that each entry in A can only be zero or 1. Further I have x being known and fixed, the same holds for b.
My question, is it a easy method for getting mathematica to spit out all possible A such that Ax=b given conditions on A.
I tried doing a number of for loops etc, however, I have completely given up after number of hours and the expectation that my effort is incorrect.
probability-or-statistics linear-algebra
$endgroup$
add a comment |
$begingroup$
I have a linear problem that I want to solve but the method is quite different from normal, the problem is still Ax=b. However,
in this instant I have A being unknown, apart from the fact that each entry in A can only be zero or 1. Further I have x being known and fixed, the same holds for b.
My question, is it a easy method for getting mathematica to spit out all possible A such that Ax=b given conditions on A.
I tried doing a number of for loops etc, however, I have completely given up after number of hours and the expectation that my effort is incorrect.
probability-or-statistics linear-algebra
$endgroup$
$begingroup$
You should be able to useTuples+Partition(after perhaps filtering out nonsingular candidates).
$endgroup$
– J. M. is slightly pensive♦
Mar 5 at 12:13
$begingroup$
Please post a concrete example. Also note this is essentially the same as this recent MSE question
$endgroup$
– Daniel Lichtblau
Mar 5 at 16:13
add a comment |
$begingroup$
I have a linear problem that I want to solve but the method is quite different from normal, the problem is still Ax=b. However,
in this instant I have A being unknown, apart from the fact that each entry in A can only be zero or 1. Further I have x being known and fixed, the same holds for b.
My question, is it a easy method for getting mathematica to spit out all possible A such that Ax=b given conditions on A.
I tried doing a number of for loops etc, however, I have completely given up after number of hours and the expectation that my effort is incorrect.
probability-or-statistics linear-algebra
$endgroup$
I have a linear problem that I want to solve but the method is quite different from normal, the problem is still Ax=b. However,
in this instant I have A being unknown, apart from the fact that each entry in A can only be zero or 1. Further I have x being known and fixed, the same holds for b.
My question, is it a easy method for getting mathematica to spit out all possible A such that Ax=b given conditions on A.
I tried doing a number of for loops etc, however, I have completely given up after number of hours and the expectation that my effort is incorrect.
probability-or-statistics linear-algebra
probability-or-statistics linear-algebra
asked Mar 5 at 11:49
ALEXANDERALEXANDER
634518
634518
$begingroup$
You should be able to useTuples+Partition(after perhaps filtering out nonsingular candidates).
$endgroup$
– J. M. is slightly pensive♦
Mar 5 at 12:13
$begingroup$
Please post a concrete example. Also note this is essentially the same as this recent MSE question
$endgroup$
– Daniel Lichtblau
Mar 5 at 16:13
add a comment |
$begingroup$
You should be able to useTuples+Partition(after perhaps filtering out nonsingular candidates).
$endgroup$
– J. M. is slightly pensive♦
Mar 5 at 12:13
$begingroup$
Please post a concrete example. Also note this is essentially the same as this recent MSE question
$endgroup$
– Daniel Lichtblau
Mar 5 at 16:13
$begingroup$
You should be able to use
Tuples + Partition (after perhaps filtering out nonsingular candidates).$endgroup$
– J. M. is slightly pensive♦
Mar 5 at 12:13
$begingroup$
You should be able to use
Tuples + Partition (after perhaps filtering out nonsingular candidates).$endgroup$
– J. M. is slightly pensive♦
Mar 5 at 12:13
$begingroup$
Please post a concrete example. Also note this is essentially the same as this recent MSE question
$endgroup$
– Daniel Lichtblau
Mar 5 at 16:13
$begingroup$
Please post a concrete example. Also note this is essentially the same as this recent MSE question
$endgroup$
– Daniel Lichtblau
Mar 5 at 16:13
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
Here's a way to code up your problem with Solve automatically:
x = 1, 2, 3;
b = Reverse[x];
sol[x_List, b_List] /; Length[x] === Length[b] := Module[mat, vars,
mat = Array[[FormalM], Length[x]*1, 1]; (* construct a matrix of variables*)
vars = Flatten[mat];
mat /.
Solve[And @@ Thread[mat.x == b] (* Construct the equations *)
&& vars ∈ Integers && And @@ Thread[0 <= vars <= 1] (* constraints *),
vars
]
];
matrixSolutions = sol[x, b]
0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0
As you can see, 2 solutions were found. Check that the residuals of the solutions are zero vectors:
#.x - b & /@ matrixSolutions
0, 0, 0, 0, 0, 0
It works, but I don't know how scalable this approach is. Instead of Solve, you can also use NSolve and/or FindInstance (you can just replace Solve with any of those two functions in the code above).
$endgroup$
add a comment |
$begingroup$
Pretty much the same questions as
FrobeniusSolve with solutions only being 0 or 1 being acceptable
Using @Sjoerd's problem
x = 1, 2, 3;
b = Reverse[x];
Can write solution as
res = Tuples@(Select[FrobeniusSolve[x, #], Max@# <= 1 &] & /@ b)
(* 0, 0, 1, 0, 1, 0, 1, 0, 0,
1, 1, 0, 0, 1, 0, 1, 0, 0 *)
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192643%2fall-possible-a-of-ax-b-with-constraints-on-a%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Here's a way to code up your problem with Solve automatically:
x = 1, 2, 3;
b = Reverse[x];
sol[x_List, b_List] /; Length[x] === Length[b] := Module[mat, vars,
mat = Array[[FormalM], Length[x]*1, 1]; (* construct a matrix of variables*)
vars = Flatten[mat];
mat /.
Solve[And @@ Thread[mat.x == b] (* Construct the equations *)
&& vars ∈ Integers && And @@ Thread[0 <= vars <= 1] (* constraints *),
vars
]
];
matrixSolutions = sol[x, b]
0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0
As you can see, 2 solutions were found. Check that the residuals of the solutions are zero vectors:
#.x - b & /@ matrixSolutions
0, 0, 0, 0, 0, 0
It works, but I don't know how scalable this approach is. Instead of Solve, you can also use NSolve and/or FindInstance (you can just replace Solve with any of those two functions in the code above).
$endgroup$
add a comment |
$begingroup$
Here's a way to code up your problem with Solve automatically:
x = 1, 2, 3;
b = Reverse[x];
sol[x_List, b_List] /; Length[x] === Length[b] := Module[mat, vars,
mat = Array[[FormalM], Length[x]*1, 1]; (* construct a matrix of variables*)
vars = Flatten[mat];
mat /.
Solve[And @@ Thread[mat.x == b] (* Construct the equations *)
&& vars ∈ Integers && And @@ Thread[0 <= vars <= 1] (* constraints *),
vars
]
];
matrixSolutions = sol[x, b]
0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0
As you can see, 2 solutions were found. Check that the residuals of the solutions are zero vectors:
#.x - b & /@ matrixSolutions
0, 0, 0, 0, 0, 0
It works, but I don't know how scalable this approach is. Instead of Solve, you can also use NSolve and/or FindInstance (you can just replace Solve with any of those two functions in the code above).
$endgroup$
add a comment |
$begingroup$
Here's a way to code up your problem with Solve automatically:
x = 1, 2, 3;
b = Reverse[x];
sol[x_List, b_List] /; Length[x] === Length[b] := Module[mat, vars,
mat = Array[[FormalM], Length[x]*1, 1]; (* construct a matrix of variables*)
vars = Flatten[mat];
mat /.
Solve[And @@ Thread[mat.x == b] (* Construct the equations *)
&& vars ∈ Integers && And @@ Thread[0 <= vars <= 1] (* constraints *),
vars
]
];
matrixSolutions = sol[x, b]
0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0
As you can see, 2 solutions were found. Check that the residuals of the solutions are zero vectors:
#.x - b & /@ matrixSolutions
0, 0, 0, 0, 0, 0
It works, but I don't know how scalable this approach is. Instead of Solve, you can also use NSolve and/or FindInstance (you can just replace Solve with any of those two functions in the code above).
$endgroup$
Here's a way to code up your problem with Solve automatically:
x = 1, 2, 3;
b = Reverse[x];
sol[x_List, b_List] /; Length[x] === Length[b] := Module[mat, vars,
mat = Array[[FormalM], Length[x]*1, 1]; (* construct a matrix of variables*)
vars = Flatten[mat];
mat /.
Solve[And @@ Thread[mat.x == b] (* Construct the equations *)
&& vars ∈ Integers && And @@ Thread[0 <= vars <= 1] (* constraints *),
vars
]
];
matrixSolutions = sol[x, b]
0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0
As you can see, 2 solutions were found. Check that the residuals of the solutions are zero vectors:
#.x - b & /@ matrixSolutions
0, 0, 0, 0, 0, 0
It works, but I don't know how scalable this approach is. Instead of Solve, you can also use NSolve and/or FindInstance (you can just replace Solve with any of those two functions in the code above).
edited Mar 5 at 17:09
MarcoB
38.4k557115
38.4k557115
answered Mar 5 at 12:38
Sjoerd SmitSjoerd Smit
4,255816
4,255816
add a comment |
add a comment |
$begingroup$
Pretty much the same questions as
FrobeniusSolve with solutions only being 0 or 1 being acceptable
Using @Sjoerd's problem
x = 1, 2, 3;
b = Reverse[x];
Can write solution as
res = Tuples@(Select[FrobeniusSolve[x, #], Max@# <= 1 &] & /@ b)
(* 0, 0, 1, 0, 1, 0, 1, 0, 0,
1, 1, 0, 0, 1, 0, 1, 0, 0 *)
$endgroup$
add a comment |
$begingroup$
Pretty much the same questions as
FrobeniusSolve with solutions only being 0 or 1 being acceptable
Using @Sjoerd's problem
x = 1, 2, 3;
b = Reverse[x];
Can write solution as
res = Tuples@(Select[FrobeniusSolve[x, #], Max@# <= 1 &] & /@ b)
(* 0, 0, 1, 0, 1, 0, 1, 0, 0,
1, 1, 0, 0, 1, 0, 1, 0, 0 *)
$endgroup$
add a comment |
$begingroup$
Pretty much the same questions as
FrobeniusSolve with solutions only being 0 or 1 being acceptable
Using @Sjoerd's problem
x = 1, 2, 3;
b = Reverse[x];
Can write solution as
res = Tuples@(Select[FrobeniusSolve[x, #], Max@# <= 1 &] & /@ b)
(* 0, 0, 1, 0, 1, 0, 1, 0, 0,
1, 1, 0, 0, 1, 0, 1, 0, 0 *)
$endgroup$
Pretty much the same questions as
FrobeniusSolve with solutions only being 0 or 1 being acceptable
Using @Sjoerd's problem
x = 1, 2, 3;
b = Reverse[x];
Can write solution as
res = Tuples@(Select[FrobeniusSolve[x, #], Max@# <= 1 &] & /@ b)
(* 0, 0, 1, 0, 1, 0, 1, 0, 0,
1, 1, 0, 0, 1, 0, 1, 0, 0 *)
edited Mar 5 at 18:25
answered Mar 5 at 18:20
MikeYMikeY
3,758916
3,758916
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192643%2fall-possible-a-of-ax-b-with-constraints-on-a%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
You should be able to use
Tuples+Partition(after perhaps filtering out nonsingular candidates).$endgroup$
– J. M. is slightly pensive♦
Mar 5 at 12:13
$begingroup$
Please post a concrete example. Also note this is essentially the same as this recent MSE question
$endgroup$
– Daniel Lichtblau
Mar 5 at 16:13