How to create table with 2D function values?












3












$begingroup$


Consider some function f[x,y]. I want to create a table in the form



table = {{x1,y1,f[x1,y1]},{x1,y2,f[x1,y2]},...,{x2,y1,f[x2,y1]},{x2,y2,f[x2,y2]},...},


where $x_{i},x_{i+1}$ and $y_{i},y_{i+1}$ are separated by some distances $Delta x$, $Delta y$, and i ranges from 1 to some N.



The only way I know is to manually create a table



table=Join[Table[{x1,y,f[x1,y]},{y,y1,yN,Deltay}],Table[{x2,y,f[x2,y]},{y,y1,yN,Deltay}],...] 


However, this is not a smart way, especially for large N. Could you please provide some smarter way to build the table?










share|improve this question









$endgroup$








  • 1




    $begingroup$
    Have a look at Menu/Help/WolframDocumentation/Table. That's what will help you.
    $endgroup$
    – Alexei Boulbitch
    Mar 22 at 14:32
















3












$begingroup$


Consider some function f[x,y]. I want to create a table in the form



table = {{x1,y1,f[x1,y1]},{x1,y2,f[x1,y2]},...,{x2,y1,f[x2,y1]},{x2,y2,f[x2,y2]},...},


where $x_{i},x_{i+1}$ and $y_{i},y_{i+1}$ are separated by some distances $Delta x$, $Delta y$, and i ranges from 1 to some N.



The only way I know is to manually create a table



table=Join[Table[{x1,y,f[x1,y]},{y,y1,yN,Deltay}],Table[{x2,y,f[x2,y]},{y,y1,yN,Deltay}],...] 


However, this is not a smart way, especially for large N. Could you please provide some smarter way to build the table?










share|improve this question









$endgroup$








  • 1




    $begingroup$
    Have a look at Menu/Help/WolframDocumentation/Table. That's what will help you.
    $endgroup$
    – Alexei Boulbitch
    Mar 22 at 14:32














3












3








3





$begingroup$


Consider some function f[x,y]. I want to create a table in the form



table = {{x1,y1,f[x1,y1]},{x1,y2,f[x1,y2]},...,{x2,y1,f[x2,y1]},{x2,y2,f[x2,y2]},...},


where $x_{i},x_{i+1}$ and $y_{i},y_{i+1}$ are separated by some distances $Delta x$, $Delta y$, and i ranges from 1 to some N.



The only way I know is to manually create a table



table=Join[Table[{x1,y,f[x1,y]},{y,y1,yN,Deltay}],Table[{x2,y,f[x2,y]},{y,y1,yN,Deltay}],...] 


However, this is not a smart way, especially for large N. Could you please provide some smarter way to build the table?










share|improve this question









$endgroup$




Consider some function f[x,y]. I want to create a table in the form



table = {{x1,y1,f[x1,y1]},{x1,y2,f[x1,y2]},...,{x2,y1,f[x2,y1]},{x2,y2,f[x2,y2]},...},


where $x_{i},x_{i+1}$ and $y_{i},y_{i+1}$ are separated by some distances $Delta x$, $Delta y$, and i ranges from 1 to some N.



The only way I know is to manually create a table



table=Join[Table[{x1,y,f[x1,y]},{y,y1,yN,Deltay}],Table[{x2,y,f[x2,y]},{y,y1,yN,Deltay}],...] 


However, this is not a smart way, especially for large N. Could you please provide some smarter way to build the table?







table






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 14:23









John TaylorJohn Taylor

766211




766211








  • 1




    $begingroup$
    Have a look at Menu/Help/WolframDocumentation/Table. That's what will help you.
    $endgroup$
    – Alexei Boulbitch
    Mar 22 at 14:32














  • 1




    $begingroup$
    Have a look at Menu/Help/WolframDocumentation/Table. That's what will help you.
    $endgroup$
    – Alexei Boulbitch
    Mar 22 at 14:32








1




1




$begingroup$
Have a look at Menu/Help/WolframDocumentation/Table. That's what will help you.
$endgroup$
– Alexei Boulbitch
Mar 22 at 14:32




$begingroup$
Have a look at Menu/Help/WolframDocumentation/Table. That's what will help you.
$endgroup$
– Alexei Boulbitch
Mar 22 at 14:32










2 Answers
2






active

oldest

votes


















6












$begingroup$

x1 = 1; xN = 9; Δx = 3;
y1 = 0; yN = 5; Δy = 1;

table = Join @@ Table[{i, j, f[i, j]}, {i, x1, xN, Δx}, {j, y1, yN, Δy}]



{{1, 0, f[1, 0]}, {1, 1, f[1, 1]}, {1, 2, f[1, 2]}, {1, 3,
f[1, 3]}, {1, 4, f[1, 4]}, {1, 5, f[1, 5]},

{4, 0, f[4, 0]}, {4, 1,
f[4, 1]}, {4, 2, f[4, 2]}, {4, 3, f[4, 3]}, {4, 4, f[4, 4]}, {4, 5,
f[4, 5]},

{7, 0, f[7, 0]}, {7, 1, f[7, 1]}, {7, 2, f[7, 2]}, {7, 3,
f[7, 3]}, {7, 4, f[7, 4]}, {7, 5, f[7, 5]}}




Also



table2 = {##, f @ ##} & @@@ Tuples[{Range[x1, xN, Δx], Range[y1, yN, Δy]}]
table2 == table



True







share|improve this answer











$endgroup$





















    2












    $begingroup$

    This would be a nice answer (using the Outer product to create the 2D array):



    x1 = 1; xN = 9; dx = 3;
    y1 = 0; yN = 5; dy = 1;
    Partition[Flatten[
    Outer[Through[{List, f}[#1, #2]] &, Range[x1, xN, dx], Range[y1, yN, dy]]], 3]


    except that Outer returns too many levels -- hence the Flatten and Partition are needed to remove the extra brackets. Answer is the same as kglr's.






    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%2f193773%2fhow-to-create-table-with-2d-function-values%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$

      x1 = 1; xN = 9; Δx = 3;
      y1 = 0; yN = 5; Δy = 1;

      table = Join @@ Table[{i, j, f[i, j]}, {i, x1, xN, Δx}, {j, y1, yN, Δy}]



      {{1, 0, f[1, 0]}, {1, 1, f[1, 1]}, {1, 2, f[1, 2]}, {1, 3,
      f[1, 3]}, {1, 4, f[1, 4]}, {1, 5, f[1, 5]},

      {4, 0, f[4, 0]}, {4, 1,
      f[4, 1]}, {4, 2, f[4, 2]}, {4, 3, f[4, 3]}, {4, 4, f[4, 4]}, {4, 5,
      f[4, 5]},

      {7, 0, f[7, 0]}, {7, 1, f[7, 1]}, {7, 2, f[7, 2]}, {7, 3,
      f[7, 3]}, {7, 4, f[7, 4]}, {7, 5, f[7, 5]}}




      Also



      table2 = {##, f @ ##} & @@@ Tuples[{Range[x1, xN, Δx], Range[y1, yN, Δy]}]
      table2 == table



      True







      share|improve this answer











      $endgroup$


















        6












        $begingroup$

        x1 = 1; xN = 9; Δx = 3;
        y1 = 0; yN = 5; Δy = 1;

        table = Join @@ Table[{i, j, f[i, j]}, {i, x1, xN, Δx}, {j, y1, yN, Δy}]



        {{1, 0, f[1, 0]}, {1, 1, f[1, 1]}, {1, 2, f[1, 2]}, {1, 3,
        f[1, 3]}, {1, 4, f[1, 4]}, {1, 5, f[1, 5]},

        {4, 0, f[4, 0]}, {4, 1,
        f[4, 1]}, {4, 2, f[4, 2]}, {4, 3, f[4, 3]}, {4, 4, f[4, 4]}, {4, 5,
        f[4, 5]},

        {7, 0, f[7, 0]}, {7, 1, f[7, 1]}, {7, 2, f[7, 2]}, {7, 3,
        f[7, 3]}, {7, 4, f[7, 4]}, {7, 5, f[7, 5]}}




        Also



        table2 = {##, f @ ##} & @@@ Tuples[{Range[x1, xN, Δx], Range[y1, yN, Δy]}]
        table2 == table



        True







        share|improve this answer











        $endgroup$
















          6












          6








          6





          $begingroup$

          x1 = 1; xN = 9; Δx = 3;
          y1 = 0; yN = 5; Δy = 1;

          table = Join @@ Table[{i, j, f[i, j]}, {i, x1, xN, Δx}, {j, y1, yN, Δy}]



          {{1, 0, f[1, 0]}, {1, 1, f[1, 1]}, {1, 2, f[1, 2]}, {1, 3,
          f[1, 3]}, {1, 4, f[1, 4]}, {1, 5, f[1, 5]},

          {4, 0, f[4, 0]}, {4, 1,
          f[4, 1]}, {4, 2, f[4, 2]}, {4, 3, f[4, 3]}, {4, 4, f[4, 4]}, {4, 5,
          f[4, 5]},

          {7, 0, f[7, 0]}, {7, 1, f[7, 1]}, {7, 2, f[7, 2]}, {7, 3,
          f[7, 3]}, {7, 4, f[7, 4]}, {7, 5, f[7, 5]}}




          Also



          table2 = {##, f @ ##} & @@@ Tuples[{Range[x1, xN, Δx], Range[y1, yN, Δy]}]
          table2 == table



          True







          share|improve this answer











          $endgroup$



          x1 = 1; xN = 9; Δx = 3;
          y1 = 0; yN = 5; Δy = 1;

          table = Join @@ Table[{i, j, f[i, j]}, {i, x1, xN, Δx}, {j, y1, yN, Δy}]



          {{1, 0, f[1, 0]}, {1, 1, f[1, 1]}, {1, 2, f[1, 2]}, {1, 3,
          f[1, 3]}, {1, 4, f[1, 4]}, {1, 5, f[1, 5]},

          {4, 0, f[4, 0]}, {4, 1,
          f[4, 1]}, {4, 2, f[4, 2]}, {4, 3, f[4, 3]}, {4, 4, f[4, 4]}, {4, 5,
          f[4, 5]},

          {7, 0, f[7, 0]}, {7, 1, f[7, 1]}, {7, 2, f[7, 2]}, {7, 3,
          f[7, 3]}, {7, 4, f[7, 4]}, {7, 5, f[7, 5]}}




          Also



          table2 = {##, f @ ##} & @@@ Tuples[{Range[x1, xN, Δx], Range[y1, yN, Δy]}]
          table2 == table



          True








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 22 at 14:36

























          answered Mar 22 at 14:30









          kglrkglr

          189k10206424




          189k10206424























              2












              $begingroup$

              This would be a nice answer (using the Outer product to create the 2D array):



              x1 = 1; xN = 9; dx = 3;
              y1 = 0; yN = 5; dy = 1;
              Partition[Flatten[
              Outer[Through[{List, f}[#1, #2]] &, Range[x1, xN, dx], Range[y1, yN, dy]]], 3]


              except that Outer returns too many levels -- hence the Flatten and Partition are needed to remove the extra brackets. Answer is the same as kglr's.






              share|improve this answer









              $endgroup$


















                2












                $begingroup$

                This would be a nice answer (using the Outer product to create the 2D array):



                x1 = 1; xN = 9; dx = 3;
                y1 = 0; yN = 5; dy = 1;
                Partition[Flatten[
                Outer[Through[{List, f}[#1, #2]] &, Range[x1, xN, dx], Range[y1, yN, dy]]], 3]


                except that Outer returns too many levels -- hence the Flatten and Partition are needed to remove the extra brackets. Answer is the same as kglr's.






                share|improve this answer









                $endgroup$
















                  2












                  2








                  2





                  $begingroup$

                  This would be a nice answer (using the Outer product to create the 2D array):



                  x1 = 1; xN = 9; dx = 3;
                  y1 = 0; yN = 5; dy = 1;
                  Partition[Flatten[
                  Outer[Through[{List, f}[#1, #2]] &, Range[x1, xN, dx], Range[y1, yN, dy]]], 3]


                  except that Outer returns too many levels -- hence the Flatten and Partition are needed to remove the extra brackets. Answer is the same as kglr's.






                  share|improve this answer









                  $endgroup$



                  This would be a nice answer (using the Outer product to create the 2D array):



                  x1 = 1; xN = 9; dx = 3;
                  y1 = 0; yN = 5; dy = 1;
                  Partition[Flatten[
                  Outer[Through[{List, f}[#1, #2]] &, Range[x1, xN, dx], Range[y1, yN, dy]]], 3]


                  except that Outer returns too many levels -- hence the Flatten and Partition are needed to remove the extra brackets. Answer is the same as kglr's.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 22 at 16:06









                  bill sbill s

                  54.7k377157




                  54.7k377157






























                      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%2f193773%2fhow-to-create-table-with-2d-function-values%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

                      Plaza Victoria

                      In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                      How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...