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

Split a number into equal parts given the number of parts

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

Levi-Civita symbol: 3D matrix

I've given my players a lot of magic items. Is it reasonable for me to give them harder encounters?

Correct physics behind the colors on CD (compact disc)?

Can the Shape Water Cantrip be used to manipulate blood?

Difference between 'stomach' and 'uterus'

Plagiarism of code by other PhD student

Being asked to review a paper in conference one has submitted to

Sometimes a banana is just a banana

Canadian citizen, on US no-fly list. What can I do in order to be allowed on flights which go through US airspace?

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

Misplaced tyre lever - alternatives?

How do I deal with being envious of my own players?

It doesn't matter the side you see it

How to get the first element while continue streaming?

Specific Chinese carabiner QA?

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

I encountered my boss during an on-site interview at another company. Should I bring it up when seeing him next time?

Where is this quote about overcoming the impossible said in "Interstellar"?

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

Can an earth elemental drown/bury its opponent underground using earth glide?

3.5% Interest Student Loan or use all of my savings on Tuition?

How can I handle a player who pre-plans arguments about my rulings on RAW?



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,850715




          3,850715























              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,258614




                  3,258614






























                      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

                      Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

                      VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

                      Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...