All possible A of Ax=b with constraints on AFrobeniusSolve with solutions only being 0 or 1 being...

Should I use HTTPS on a domain that will only be used for redirection?

Is the NES controller port identical to the port on a Wii remote?

Misplaced tyre lever - alternatives?

How to disable or uninstall iTunes under High Sierra without disabling SIP

Can a space-faring robot still function over a billion years?

The need of reserving one's ability in job interviews

Is every open circuit a capacitor?

A bug in Excel? Conditional formatting for marking duplicates also highlights unique value

GPL code private and stolen

How to fix my table, centering of columns

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Relationship between the symmetry number of a molecule as used in rotational spectroscopy and point group

How do you say “my friend is throwing a party, do you wanna come?” in german

I can't die. Who am I?

Why are special aircraft used for the carriers in the United States Navy?

Did Amazon pay $0 in taxes last year?

Why doesn't "adolescent" take any articles in "listen to adolescent agonising"?

Is there a way to find out the age of climbing ropes?

Are there other characters in the Star Wars universe who had damaged bodies and needed to wear an outfit like Darth Vader?

Create chunks from an array

It doesn't matter the side you see it

When to use mean vs median

Split a number into equal parts given the number of parts

Book about a time-travel war fought by computers



All possible A of Ax=b with constraints on A


FrobeniusSolve with solutions only being 0 or 1 being acceptableHow to augment the realm of functions Mathematica thinks it knows how to integrate symbolicallyEstimate error on slope of linear regression given data with associated uncertaintyGenerating a list of integers that roughly satisfy a distributionChoosing appropriate WorkingPrecision when solving numerical system of equations“Reduce” works fine for a non-linear system with 9 equations, but cannot solve it if 10 equations. Any ways to improve the code?Finding mean of data sets with unequal lengthIs it possible to speedup these simple linear algebra operationsAnalytic inversion of linear systemObtaining the determinant from a LinearSolveFunction objectPlotting confidence interval from P values (from DistributionFitTest) for 2 parameters













5












$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.










share|improve this question









$endgroup$












  • $begingroup$
    You should be able to use Tuples[] + Partition[] (after perhaps filtering out nonsingular candidates).
    $endgroup$
    – J. M. is computer-less
    yesterday










  • $begingroup$
    Please post a concrete example. Also note this is essentially the same as this recent MSE question
    $endgroup$
    – Daniel Lichtblau
    yesterday
















5












$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.










share|improve this question









$endgroup$












  • $begingroup$
    You should be able to use Tuples[] + Partition[] (after perhaps filtering out nonsingular candidates).
    $endgroup$
    – J. M. is computer-less
    yesterday










  • $begingroup$
    Please post a concrete example. Also note this is essentially the same as this recent MSE question
    $endgroup$
    – Daniel Lichtblau
    yesterday














5












5








5





$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.










share|improve this question









$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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









ALEXANDERALEXANDER

634518




634518












  • $begingroup$
    You should be able to use Tuples[] + Partition[] (after perhaps filtering out nonsingular candidates).
    $endgroup$
    – J. M. is computer-less
    yesterday










  • $begingroup$
    Please post a concrete example. Also note this is essentially the same as this recent MSE question
    $endgroup$
    – Daniel Lichtblau
    yesterday


















  • $begingroup$
    You should be able to use Tuples[] + Partition[] (after perhaps filtering out nonsingular candidates).
    $endgroup$
    – J. M. is computer-less
    yesterday










  • $begingroup$
    Please post a concrete example. Also note this is essentially the same as this recent MSE question
    $endgroup$
    – Daniel Lichtblau
    yesterday
















$begingroup$
You should be able to use Tuples[] + Partition[] (after perhaps filtering out nonsingular candidates).
$endgroup$
– J. M. is computer-less
yesterday




$begingroup$
You should be able to use Tuples[] + Partition[] (after perhaps filtering out nonsingular candidates).
$endgroup$
– J. M. is computer-less
yesterday












$begingroup$
Please post a concrete example. Also note this is essentially the same as this recent MSE question
$endgroup$
– Daniel Lichtblau
yesterday




$begingroup$
Please post a concrete example. Also note this is essentially the same as this recent MSE question
$endgroup$
– Daniel Lichtblau
yesterday










2 Answers
2






active

oldest

votes


















6












$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).






share|improve this answer











$endgroup$





















    1












    $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}}} *)





    share|improve this answer











    $endgroup$













      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      6












      $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).






      share|improve this answer











      $endgroup$


















        6












        $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).






        share|improve this answer











        $endgroup$
















          6












          6








          6





          $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).






          share|improve this answer











          $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).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday









          MarcoB

          36.9k556113




          36.9k556113










          answered yesterday









          Sjoerd SmitSjoerd Smit

          3,820715




          3,820715























              1












              $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}}} *)





              share|improve this answer











              $endgroup$


















                1












                $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}}} *)





                share|improve this answer











                $endgroup$
















                  1












                  1








                  1





                  $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}}} *)





                  share|improve this answer











                  $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}}} *)






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited yesterday

























                  answered yesterday









                  MikeYMikeY

                  3,248614




                  3,248614






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Installing LyX: “No textclass is found.”LyX installation error- text class not found- 'Reconfigure' or...

                      (1602) Indiana Índice Designación y nombre Características orbitales Véase...

                      Universidad Autónoma de Occidente Índice Historia Campus Facultades Programas Académicos Medios de...