How do I construct an nxn matrix?












6















I'm trying to create a large nxn matrix but I am unable to find a technique which will make it easier rather than doing it manually, any ideas?










share|improve this question









New contributor




john is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • If the data is stored in a file, you can use pgfplotstable or csvsimple to format it. OTOH, pgfplotstable can be a pain to customize. For example columns/name/.style={...} is used a lot.

    – John Kormylo
    23 hours ago


















6















I'm trying to create a large nxn matrix but I am unable to find a technique which will make it easier rather than doing it manually, any ideas?










share|improve this question









New contributor




john is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • If the data is stored in a file, you can use pgfplotstable or csvsimple to format it. OTOH, pgfplotstable can be a pain to customize. For example columns/name/.style={...} is used a lot.

    – John Kormylo
    23 hours ago
















6












6








6


0






I'm trying to create a large nxn matrix but I am unable to find a technique which will make it easier rather than doing it manually, any ideas?










share|improve this question









New contributor




john is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I'm trying to create a large nxn matrix but I am unable to find a technique which will make it easier rather than doing it manually, any ideas?







matrices






share|improve this question









New contributor




john is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




john is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









Bernard

172k776204




172k776204






New contributor




john is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









johnjohn

413




413




New contributor




john is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





john is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






john is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • If the data is stored in a file, you can use pgfplotstable or csvsimple to format it. OTOH, pgfplotstable can be a pain to customize. For example columns/name/.style={...} is used a lot.

    – John Kormylo
    23 hours ago





















  • If the data is stored in a file, you can use pgfplotstable or csvsimple to format it. OTOH, pgfplotstable can be a pain to customize. For example columns/name/.style={...} is used a lot.

    – John Kormylo
    23 hours ago



















If the data is stored in a file, you can use pgfplotstable or csvsimple to format it. OTOH, pgfplotstable can be a pain to customize. For example columns/name/.style={...} is used a lot.

– John Kormylo
23 hours ago







If the data is stored in a file, you can use pgfplotstable or csvsimple to format it. OTOH, pgfplotstable can be a pain to customize. For example columns/name/.style={...} is used a lot.

– John Kormylo
23 hours ago












4 Answers
4






active

oldest

votes


















6














This prints a random matrix with the specified size.



The keys are size (mandatory), lb for the lower bound on the random integers (default 0), ub for the upper bound on the random integers (default 20).



documentclass{article}
usepackage{amsmath}
usepackage{xparse}

ExplSyntaxOn

NewDocumentCommand{bigmatrix}{m}
{
group_begin:
keys_set:nn { john/bigmatrix } { #1 }
john_bigmatrix:
group_end:
}

tl_new:N l__john_bigmatrix_tl

keys_define:nn { john/bigmatrix }
{
size .int_set:N = l__john_bigmatrix_size_int,
lb .int_set:N = l__john_bigmatrix_lb_int,
ub .int_set:N = l__john_bigmatrix_ub_int,
lb .initial:n = 0,
ub .initial:n = 20,
}

cs_new_protected:Nn john_bigmatrix:
{
int_compare:nT { l__john_bigmatrix_size_int > value{MaxMatrixCols} }
{
setcounter{MaxMatrixCols}{l__john_bigmatrix_size_int}
}
int_step_function:nN { l__john_bigmatrix_size_int } __john_bigmatrix_row:n
begin{bmatrix}
l__john_bigmatrix_tl
end{bmatrix}
}

cs_new_protected:Nn __john_bigmatrix_row:n
{
tl_put_right:Nx l__john_bigmatrix_tl
{
int_rand:nn { l__john_bigmatrix_lb_int } { l__john_bigmatrix_ub_int }
}
prg_replicate:nn { l__john_bigmatrix_size_int - 1 }
{
tl_put_right:Nx l__john_bigmatrix_tl
{
&
int_rand:nn { l__john_bigmatrix_lb_int } { l__john_bigmatrix_ub_int }
}
}
tl_put_right:Nn l__john_bigmatrix_tl { \ }
}

ExplSyntaxOff

begin{document}

$bigmatrix{size=5}$ $bigmatrix{size=6,lb=-12,ub=12}$

bigskip

$bigmatrix{size=15,ub=50}$

end{document}


enter image description here






share|improve this answer































    4














    Use Mathematica for example,



    IdentityMatrix[10]  // TeXForm


    And copy the output for LaTeX as follows.



    documentclass[border=12pt,12pt]{standalone}
    usepackage{amsmath}
    begin{document}
    $A=
    begin{pmatrix}
    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
    0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
    0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \
    0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \
    0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \
    0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \
    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \
    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \
    end{pmatrix}
    $
    end{document}


    enter image description here






    share|improve this answer
























    • Note that: LaTeX generates some errors for n x n matrices with n>10.

      – The Inventor of God
      yesterday





















    3














    Use the computer algebra system Sage along with the sagetex package. First, here is the code:



    documentclass{article}
    usepackage{sagetex}
    begin{document}
    begin{sagesilent}
    latex.matrix_delimiters(left='[', right=']')
    A = Matrix([[0,-1,-1],[-1,-1,0],[-1,0,1],[1,0,0],[0,0,-1],[-1,2,1]])
    B = Matrix.identity(4)
    C = random_matrix(ZZ,4,3)
    D = random_matrix(QQ,3,4)
    end{sagesilent}
    The matrix $A=sage{A}$ was input by hand. The matrix $B=sage{B}$ is defined in Sage.
    The matrix $C=sage{C}$ is $4 times 4$ matrix consisting of integers determined
    at random. The matrix $D=sage{D}$ is a $3 times 4$ matrix consisting of rational
    numbers determined randomly.

    Computing $C cdot D= sage{C*D}$ is easy. You can compute use Sage to test if
    matrices are singular or nonsingular and even calculate their inverses.
    Sage will take care of the calculations but
    you'll have to spend time making the output look a little nicer.
    end{document}


    Next, here is the output. Since some of my matrix constructions are random, it should look different than your run of the same code.
    enter image description here



    Finally, the basic construction is C = random_matrix(ZZ,4,3) where




    1. C is the matrix you're defining

    2. 4 is the number of rows

    3. 3 is the number of columns

    4. ZZ is for entries to be integers, QQ for rational, RR for real, CC for complex. You can also work with finite fields. See the documentation.


    Note that I've shown how matrix A can be defined by you, entry by entry while B shows how Sage will create the 4x4 identity matrix for you. After you have your matrices set up, Sage will do the calculations as well. This prevents careless mistakes from creeping into your document. Sage isn't part of the LaTeX distribution but you can access it online with a free Cocalc account here. It is possible to install Sage on your computer so you don't need Cocalc. That is more difficult to get up and running. Some important documentation for working with matrices in SAGE is here, here, here, and here. Sage has no problem with big matrices but displaying them on the page becomes problematic. Using usepackage{fullpage} in your code can free up space so that I print a 20 by 20 matrix.






    share|improve this answer


























    • Sorry. I have not tried it yet, can sagetex produce .tex (instead of .pdf) file that can be rendered by MathJaX on web browsers?

      – The Inventor of God
      8 hours ago








    • 1





      This is outside of my knowledge. However, this page from the Sagemath site mentions MathJax as follows "The eval function of this class converts a Sage object to its LaTeX representation and then wraps it in HTML that invokes the CSS “math” class, which then employs MathJax.". So it sounds like it might but I don't know for sure.

      – DJP
      3 hours ago











    • No problem. Thank you!

      – The Inventor of God
      2 hours ago



















    2














    Matrices of normal random numbers using knitr:



    documentclass{article}
    usepackage{amsmath}

    <<bmatrix,echo=F>>=
    options(digits=2)
    bmatrix <- function(matr) {
    printmrow <- function(x) {cat(cat(x,sep=" & "),"\\ n")}
    cat("\begin{bmatrix}","n")
    body <- apply(matr,1,printmrow)
    cat("\end{bmatrix}")}
    @

    begin{document}
    [ A =
    <<echo=F,results='asis'>>=
    bmatrix(round(matrix(rnorm(6), 2 ,3),3))
    @
    ]
    [ B =
    <<echo=F,results='asis'>>=
    bmatrix(round(matrix(abs(rnorm(120)), 12 ,10),1))
    @
    ]
    setcounter{MaxMatrixCols}{12}
    [ C =
    <<echo=F,results='asis'>>=
    bmatrix(round(matrix(abs(rnorm(144)), 12 ,12),1))
    @
    ]
    end{document}



    enter image description here







    share|improve this answer

























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "85"
      };
      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
      });


      }
      });






      john is a new contributor. Be nice, and check out our Code of Conduct.










      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477728%2fhow-do-i-construct-an-nxn-matrix%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      6














      This prints a random matrix with the specified size.



      The keys are size (mandatory), lb for the lower bound on the random integers (default 0), ub for the upper bound on the random integers (default 20).



      documentclass{article}
      usepackage{amsmath}
      usepackage{xparse}

      ExplSyntaxOn

      NewDocumentCommand{bigmatrix}{m}
      {
      group_begin:
      keys_set:nn { john/bigmatrix } { #1 }
      john_bigmatrix:
      group_end:
      }

      tl_new:N l__john_bigmatrix_tl

      keys_define:nn { john/bigmatrix }
      {
      size .int_set:N = l__john_bigmatrix_size_int,
      lb .int_set:N = l__john_bigmatrix_lb_int,
      ub .int_set:N = l__john_bigmatrix_ub_int,
      lb .initial:n = 0,
      ub .initial:n = 20,
      }

      cs_new_protected:Nn john_bigmatrix:
      {
      int_compare:nT { l__john_bigmatrix_size_int > value{MaxMatrixCols} }
      {
      setcounter{MaxMatrixCols}{l__john_bigmatrix_size_int}
      }
      int_step_function:nN { l__john_bigmatrix_size_int } __john_bigmatrix_row:n
      begin{bmatrix}
      l__john_bigmatrix_tl
      end{bmatrix}
      }

      cs_new_protected:Nn __john_bigmatrix_row:n
      {
      tl_put_right:Nx l__john_bigmatrix_tl
      {
      int_rand:nn { l__john_bigmatrix_lb_int } { l__john_bigmatrix_ub_int }
      }
      prg_replicate:nn { l__john_bigmatrix_size_int - 1 }
      {
      tl_put_right:Nx l__john_bigmatrix_tl
      {
      &
      int_rand:nn { l__john_bigmatrix_lb_int } { l__john_bigmatrix_ub_int }
      }
      }
      tl_put_right:Nn l__john_bigmatrix_tl { \ }
      }

      ExplSyntaxOff

      begin{document}

      $bigmatrix{size=5}$ $bigmatrix{size=6,lb=-12,ub=12}$

      bigskip

      $bigmatrix{size=15,ub=50}$

      end{document}


      enter image description here






      share|improve this answer




























        6














        This prints a random matrix with the specified size.



        The keys are size (mandatory), lb for the lower bound on the random integers (default 0), ub for the upper bound on the random integers (default 20).



        documentclass{article}
        usepackage{amsmath}
        usepackage{xparse}

        ExplSyntaxOn

        NewDocumentCommand{bigmatrix}{m}
        {
        group_begin:
        keys_set:nn { john/bigmatrix } { #1 }
        john_bigmatrix:
        group_end:
        }

        tl_new:N l__john_bigmatrix_tl

        keys_define:nn { john/bigmatrix }
        {
        size .int_set:N = l__john_bigmatrix_size_int,
        lb .int_set:N = l__john_bigmatrix_lb_int,
        ub .int_set:N = l__john_bigmatrix_ub_int,
        lb .initial:n = 0,
        ub .initial:n = 20,
        }

        cs_new_protected:Nn john_bigmatrix:
        {
        int_compare:nT { l__john_bigmatrix_size_int > value{MaxMatrixCols} }
        {
        setcounter{MaxMatrixCols}{l__john_bigmatrix_size_int}
        }
        int_step_function:nN { l__john_bigmatrix_size_int } __john_bigmatrix_row:n
        begin{bmatrix}
        l__john_bigmatrix_tl
        end{bmatrix}
        }

        cs_new_protected:Nn __john_bigmatrix_row:n
        {
        tl_put_right:Nx l__john_bigmatrix_tl
        {
        int_rand:nn { l__john_bigmatrix_lb_int } { l__john_bigmatrix_ub_int }
        }
        prg_replicate:nn { l__john_bigmatrix_size_int - 1 }
        {
        tl_put_right:Nx l__john_bigmatrix_tl
        {
        &
        int_rand:nn { l__john_bigmatrix_lb_int } { l__john_bigmatrix_ub_int }
        }
        }
        tl_put_right:Nn l__john_bigmatrix_tl { \ }
        }

        ExplSyntaxOff

        begin{document}

        $bigmatrix{size=5}$ $bigmatrix{size=6,lb=-12,ub=12}$

        bigskip

        $bigmatrix{size=15,ub=50}$

        end{document}


        enter image description here






        share|improve this answer


























          6












          6








          6







          This prints a random matrix with the specified size.



          The keys are size (mandatory), lb for the lower bound on the random integers (default 0), ub for the upper bound on the random integers (default 20).



          documentclass{article}
          usepackage{amsmath}
          usepackage{xparse}

          ExplSyntaxOn

          NewDocumentCommand{bigmatrix}{m}
          {
          group_begin:
          keys_set:nn { john/bigmatrix } { #1 }
          john_bigmatrix:
          group_end:
          }

          tl_new:N l__john_bigmatrix_tl

          keys_define:nn { john/bigmatrix }
          {
          size .int_set:N = l__john_bigmatrix_size_int,
          lb .int_set:N = l__john_bigmatrix_lb_int,
          ub .int_set:N = l__john_bigmatrix_ub_int,
          lb .initial:n = 0,
          ub .initial:n = 20,
          }

          cs_new_protected:Nn john_bigmatrix:
          {
          int_compare:nT { l__john_bigmatrix_size_int > value{MaxMatrixCols} }
          {
          setcounter{MaxMatrixCols}{l__john_bigmatrix_size_int}
          }
          int_step_function:nN { l__john_bigmatrix_size_int } __john_bigmatrix_row:n
          begin{bmatrix}
          l__john_bigmatrix_tl
          end{bmatrix}
          }

          cs_new_protected:Nn __john_bigmatrix_row:n
          {
          tl_put_right:Nx l__john_bigmatrix_tl
          {
          int_rand:nn { l__john_bigmatrix_lb_int } { l__john_bigmatrix_ub_int }
          }
          prg_replicate:nn { l__john_bigmatrix_size_int - 1 }
          {
          tl_put_right:Nx l__john_bigmatrix_tl
          {
          &
          int_rand:nn { l__john_bigmatrix_lb_int } { l__john_bigmatrix_ub_int }
          }
          }
          tl_put_right:Nn l__john_bigmatrix_tl { \ }
          }

          ExplSyntaxOff

          begin{document}

          $bigmatrix{size=5}$ $bigmatrix{size=6,lb=-12,ub=12}$

          bigskip

          $bigmatrix{size=15,ub=50}$

          end{document}


          enter image description here






          share|improve this answer













          This prints a random matrix with the specified size.



          The keys are size (mandatory), lb for the lower bound on the random integers (default 0), ub for the upper bound on the random integers (default 20).



          documentclass{article}
          usepackage{amsmath}
          usepackage{xparse}

          ExplSyntaxOn

          NewDocumentCommand{bigmatrix}{m}
          {
          group_begin:
          keys_set:nn { john/bigmatrix } { #1 }
          john_bigmatrix:
          group_end:
          }

          tl_new:N l__john_bigmatrix_tl

          keys_define:nn { john/bigmatrix }
          {
          size .int_set:N = l__john_bigmatrix_size_int,
          lb .int_set:N = l__john_bigmatrix_lb_int,
          ub .int_set:N = l__john_bigmatrix_ub_int,
          lb .initial:n = 0,
          ub .initial:n = 20,
          }

          cs_new_protected:Nn john_bigmatrix:
          {
          int_compare:nT { l__john_bigmatrix_size_int > value{MaxMatrixCols} }
          {
          setcounter{MaxMatrixCols}{l__john_bigmatrix_size_int}
          }
          int_step_function:nN { l__john_bigmatrix_size_int } __john_bigmatrix_row:n
          begin{bmatrix}
          l__john_bigmatrix_tl
          end{bmatrix}
          }

          cs_new_protected:Nn __john_bigmatrix_row:n
          {
          tl_put_right:Nx l__john_bigmatrix_tl
          {
          int_rand:nn { l__john_bigmatrix_lb_int } { l__john_bigmatrix_ub_int }
          }
          prg_replicate:nn { l__john_bigmatrix_size_int - 1 }
          {
          tl_put_right:Nx l__john_bigmatrix_tl
          {
          &
          int_rand:nn { l__john_bigmatrix_lb_int } { l__john_bigmatrix_ub_int }
          }
          }
          tl_put_right:Nn l__john_bigmatrix_tl { \ }
          }

          ExplSyntaxOff

          begin{document}

          $bigmatrix{size=5}$ $bigmatrix{size=6,lb=-12,ub=12}$

          bigskip

          $bigmatrix{size=15,ub=50}$

          end{document}


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 22 hours ago









          egregegreg

          724k8819173222




          724k8819173222























              4














              Use Mathematica for example,



              IdentityMatrix[10]  // TeXForm


              And copy the output for LaTeX as follows.



              documentclass[border=12pt,12pt]{standalone}
              usepackage{amsmath}
              begin{document}
              $A=
              begin{pmatrix}
              1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \
              end{pmatrix}
              $
              end{document}


              enter image description here






              share|improve this answer
























              • Note that: LaTeX generates some errors for n x n matrices with n>10.

                – The Inventor of God
                yesterday


















              4














              Use Mathematica for example,



              IdentityMatrix[10]  // TeXForm


              And copy the output for LaTeX as follows.



              documentclass[border=12pt,12pt]{standalone}
              usepackage{amsmath}
              begin{document}
              $A=
              begin{pmatrix}
              1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \
              end{pmatrix}
              $
              end{document}


              enter image description here






              share|improve this answer
























              • Note that: LaTeX generates some errors for n x n matrices with n>10.

                – The Inventor of God
                yesterday
















              4












              4








              4







              Use Mathematica for example,



              IdentityMatrix[10]  // TeXForm


              And copy the output for LaTeX as follows.



              documentclass[border=12pt,12pt]{standalone}
              usepackage{amsmath}
              begin{document}
              $A=
              begin{pmatrix}
              1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \
              end{pmatrix}
              $
              end{document}


              enter image description here






              share|improve this answer













              Use Mathematica for example,



              IdentityMatrix[10]  // TeXForm


              And copy the output for LaTeX as follows.



              documentclass[border=12pt,12pt]{standalone}
              usepackage{amsmath}
              begin{document}
              $A=
              begin{pmatrix}
              1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \
              0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \
              end{pmatrix}
              $
              end{document}


              enter image description here







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered yesterday









              The Inventor of GodThe Inventor of God

              4,47211041




              4,47211041













              • Note that: LaTeX generates some errors for n x n matrices with n>10.

                – The Inventor of God
                yesterday





















              • Note that: LaTeX generates some errors for n x n matrices with n>10.

                – The Inventor of God
                yesterday



















              Note that: LaTeX generates some errors for n x n matrices with n>10.

              – The Inventor of God
              yesterday







              Note that: LaTeX generates some errors for n x n matrices with n>10.

              – The Inventor of God
              yesterday













              3














              Use the computer algebra system Sage along with the sagetex package. First, here is the code:



              documentclass{article}
              usepackage{sagetex}
              begin{document}
              begin{sagesilent}
              latex.matrix_delimiters(left='[', right=']')
              A = Matrix([[0,-1,-1],[-1,-1,0],[-1,0,1],[1,0,0],[0,0,-1],[-1,2,1]])
              B = Matrix.identity(4)
              C = random_matrix(ZZ,4,3)
              D = random_matrix(QQ,3,4)
              end{sagesilent}
              The matrix $A=sage{A}$ was input by hand. The matrix $B=sage{B}$ is defined in Sage.
              The matrix $C=sage{C}$ is $4 times 4$ matrix consisting of integers determined
              at random. The matrix $D=sage{D}$ is a $3 times 4$ matrix consisting of rational
              numbers determined randomly.

              Computing $C cdot D= sage{C*D}$ is easy. You can compute use Sage to test if
              matrices are singular or nonsingular and even calculate their inverses.
              Sage will take care of the calculations but
              you'll have to spend time making the output look a little nicer.
              end{document}


              Next, here is the output. Since some of my matrix constructions are random, it should look different than your run of the same code.
              enter image description here



              Finally, the basic construction is C = random_matrix(ZZ,4,3) where




              1. C is the matrix you're defining

              2. 4 is the number of rows

              3. 3 is the number of columns

              4. ZZ is for entries to be integers, QQ for rational, RR for real, CC for complex. You can also work with finite fields. See the documentation.


              Note that I've shown how matrix A can be defined by you, entry by entry while B shows how Sage will create the 4x4 identity matrix for you. After you have your matrices set up, Sage will do the calculations as well. This prevents careless mistakes from creeping into your document. Sage isn't part of the LaTeX distribution but you can access it online with a free Cocalc account here. It is possible to install Sage on your computer so you don't need Cocalc. That is more difficult to get up and running. Some important documentation for working with matrices in SAGE is here, here, here, and here. Sage has no problem with big matrices but displaying them on the page becomes problematic. Using usepackage{fullpage} in your code can free up space so that I print a 20 by 20 matrix.






              share|improve this answer


























              • Sorry. I have not tried it yet, can sagetex produce .tex (instead of .pdf) file that can be rendered by MathJaX on web browsers?

                – The Inventor of God
                8 hours ago








              • 1





                This is outside of my knowledge. However, this page from the Sagemath site mentions MathJax as follows "The eval function of this class converts a Sage object to its LaTeX representation and then wraps it in HTML that invokes the CSS “math” class, which then employs MathJax.". So it sounds like it might but I don't know for sure.

                – DJP
                3 hours ago











              • No problem. Thank you!

                – The Inventor of God
                2 hours ago
















              3














              Use the computer algebra system Sage along with the sagetex package. First, here is the code:



              documentclass{article}
              usepackage{sagetex}
              begin{document}
              begin{sagesilent}
              latex.matrix_delimiters(left='[', right=']')
              A = Matrix([[0,-1,-1],[-1,-1,0],[-1,0,1],[1,0,0],[0,0,-1],[-1,2,1]])
              B = Matrix.identity(4)
              C = random_matrix(ZZ,4,3)
              D = random_matrix(QQ,3,4)
              end{sagesilent}
              The matrix $A=sage{A}$ was input by hand. The matrix $B=sage{B}$ is defined in Sage.
              The matrix $C=sage{C}$ is $4 times 4$ matrix consisting of integers determined
              at random. The matrix $D=sage{D}$ is a $3 times 4$ matrix consisting of rational
              numbers determined randomly.

              Computing $C cdot D= sage{C*D}$ is easy. You can compute use Sage to test if
              matrices are singular or nonsingular and even calculate their inverses.
              Sage will take care of the calculations but
              you'll have to spend time making the output look a little nicer.
              end{document}


              Next, here is the output. Since some of my matrix constructions are random, it should look different than your run of the same code.
              enter image description here



              Finally, the basic construction is C = random_matrix(ZZ,4,3) where




              1. C is the matrix you're defining

              2. 4 is the number of rows

              3. 3 is the number of columns

              4. ZZ is for entries to be integers, QQ for rational, RR for real, CC for complex. You can also work with finite fields. See the documentation.


              Note that I've shown how matrix A can be defined by you, entry by entry while B shows how Sage will create the 4x4 identity matrix for you. After you have your matrices set up, Sage will do the calculations as well. This prevents careless mistakes from creeping into your document. Sage isn't part of the LaTeX distribution but you can access it online with a free Cocalc account here. It is possible to install Sage on your computer so you don't need Cocalc. That is more difficult to get up and running. Some important documentation for working with matrices in SAGE is here, here, here, and here. Sage has no problem with big matrices but displaying them on the page becomes problematic. Using usepackage{fullpage} in your code can free up space so that I print a 20 by 20 matrix.






              share|improve this answer


























              • Sorry. I have not tried it yet, can sagetex produce .tex (instead of .pdf) file that can be rendered by MathJaX on web browsers?

                – The Inventor of God
                8 hours ago








              • 1





                This is outside of my knowledge. However, this page from the Sagemath site mentions MathJax as follows "The eval function of this class converts a Sage object to its LaTeX representation and then wraps it in HTML that invokes the CSS “math” class, which then employs MathJax.". So it sounds like it might but I don't know for sure.

                – DJP
                3 hours ago











              • No problem. Thank you!

                – The Inventor of God
                2 hours ago














              3












              3








              3







              Use the computer algebra system Sage along with the sagetex package. First, here is the code:



              documentclass{article}
              usepackage{sagetex}
              begin{document}
              begin{sagesilent}
              latex.matrix_delimiters(left='[', right=']')
              A = Matrix([[0,-1,-1],[-1,-1,0],[-1,0,1],[1,0,0],[0,0,-1],[-1,2,1]])
              B = Matrix.identity(4)
              C = random_matrix(ZZ,4,3)
              D = random_matrix(QQ,3,4)
              end{sagesilent}
              The matrix $A=sage{A}$ was input by hand. The matrix $B=sage{B}$ is defined in Sage.
              The matrix $C=sage{C}$ is $4 times 4$ matrix consisting of integers determined
              at random. The matrix $D=sage{D}$ is a $3 times 4$ matrix consisting of rational
              numbers determined randomly.

              Computing $C cdot D= sage{C*D}$ is easy. You can compute use Sage to test if
              matrices are singular or nonsingular and even calculate their inverses.
              Sage will take care of the calculations but
              you'll have to spend time making the output look a little nicer.
              end{document}


              Next, here is the output. Since some of my matrix constructions are random, it should look different than your run of the same code.
              enter image description here



              Finally, the basic construction is C = random_matrix(ZZ,4,3) where




              1. C is the matrix you're defining

              2. 4 is the number of rows

              3. 3 is the number of columns

              4. ZZ is for entries to be integers, QQ for rational, RR for real, CC for complex. You can also work with finite fields. See the documentation.


              Note that I've shown how matrix A can be defined by you, entry by entry while B shows how Sage will create the 4x4 identity matrix for you. After you have your matrices set up, Sage will do the calculations as well. This prevents careless mistakes from creeping into your document. Sage isn't part of the LaTeX distribution but you can access it online with a free Cocalc account here. It is possible to install Sage on your computer so you don't need Cocalc. That is more difficult to get up and running. Some important documentation for working with matrices in SAGE is here, here, here, and here. Sage has no problem with big matrices but displaying them on the page becomes problematic. Using usepackage{fullpage} in your code can free up space so that I print a 20 by 20 matrix.






              share|improve this answer















              Use the computer algebra system Sage along with the sagetex package. First, here is the code:



              documentclass{article}
              usepackage{sagetex}
              begin{document}
              begin{sagesilent}
              latex.matrix_delimiters(left='[', right=']')
              A = Matrix([[0,-1,-1],[-1,-1,0],[-1,0,1],[1,0,0],[0,0,-1],[-1,2,1]])
              B = Matrix.identity(4)
              C = random_matrix(ZZ,4,3)
              D = random_matrix(QQ,3,4)
              end{sagesilent}
              The matrix $A=sage{A}$ was input by hand. The matrix $B=sage{B}$ is defined in Sage.
              The matrix $C=sage{C}$ is $4 times 4$ matrix consisting of integers determined
              at random. The matrix $D=sage{D}$ is a $3 times 4$ matrix consisting of rational
              numbers determined randomly.

              Computing $C cdot D= sage{C*D}$ is easy. You can compute use Sage to test if
              matrices are singular or nonsingular and even calculate their inverses.
              Sage will take care of the calculations but
              you'll have to spend time making the output look a little nicer.
              end{document}


              Next, here is the output. Since some of my matrix constructions are random, it should look different than your run of the same code.
              enter image description here



              Finally, the basic construction is C = random_matrix(ZZ,4,3) where




              1. C is the matrix you're defining

              2. 4 is the number of rows

              3. 3 is the number of columns

              4. ZZ is for entries to be integers, QQ for rational, RR for real, CC for complex. You can also work with finite fields. See the documentation.


              Note that I've shown how matrix A can be defined by you, entry by entry while B shows how Sage will create the 4x4 identity matrix for you. After you have your matrices set up, Sage will do the calculations as well. This prevents careless mistakes from creeping into your document. Sage isn't part of the LaTeX distribution but you can access it online with a free Cocalc account here. It is possible to install Sage on your computer so you don't need Cocalc. That is more difficult to get up and running. Some important documentation for working with matrices in SAGE is here, here, here, and here. Sage has no problem with big matrices but displaying them on the page becomes problematic. Using usepackage{fullpage} in your code can free up space so that I print a 20 by 20 matrix.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 21 hours ago

























              answered 21 hours ago









              DJPDJP

              7,82421731




              7,82421731













              • Sorry. I have not tried it yet, can sagetex produce .tex (instead of .pdf) file that can be rendered by MathJaX on web browsers?

                – The Inventor of God
                8 hours ago








              • 1





                This is outside of my knowledge. However, this page from the Sagemath site mentions MathJax as follows "The eval function of this class converts a Sage object to its LaTeX representation and then wraps it in HTML that invokes the CSS “math” class, which then employs MathJax.". So it sounds like it might but I don't know for sure.

                – DJP
                3 hours ago











              • No problem. Thank you!

                – The Inventor of God
                2 hours ago



















              • Sorry. I have not tried it yet, can sagetex produce .tex (instead of .pdf) file that can be rendered by MathJaX on web browsers?

                – The Inventor of God
                8 hours ago








              • 1





                This is outside of my knowledge. However, this page from the Sagemath site mentions MathJax as follows "The eval function of this class converts a Sage object to its LaTeX representation and then wraps it in HTML that invokes the CSS “math” class, which then employs MathJax.". So it sounds like it might but I don't know for sure.

                – DJP
                3 hours ago











              • No problem. Thank you!

                – The Inventor of God
                2 hours ago

















              Sorry. I have not tried it yet, can sagetex produce .tex (instead of .pdf) file that can be rendered by MathJaX on web browsers?

              – The Inventor of God
              8 hours ago







              Sorry. I have not tried it yet, can sagetex produce .tex (instead of .pdf) file that can be rendered by MathJaX on web browsers?

              – The Inventor of God
              8 hours ago






              1




              1





              This is outside of my knowledge. However, this page from the Sagemath site mentions MathJax as follows "The eval function of this class converts a Sage object to its LaTeX representation and then wraps it in HTML that invokes the CSS “math” class, which then employs MathJax.". So it sounds like it might but I don't know for sure.

              – DJP
              3 hours ago





              This is outside of my knowledge. However, this page from the Sagemath site mentions MathJax as follows "The eval function of this class converts a Sage object to its LaTeX representation and then wraps it in HTML that invokes the CSS “math” class, which then employs MathJax.". So it sounds like it might but I don't know for sure.

              – DJP
              3 hours ago













              No problem. Thank you!

              – The Inventor of God
              2 hours ago





              No problem. Thank you!

              – The Inventor of God
              2 hours ago











              2














              Matrices of normal random numbers using knitr:



              documentclass{article}
              usepackage{amsmath}

              <<bmatrix,echo=F>>=
              options(digits=2)
              bmatrix <- function(matr) {
              printmrow <- function(x) {cat(cat(x,sep=" & "),"\\ n")}
              cat("\begin{bmatrix}","n")
              body <- apply(matr,1,printmrow)
              cat("\end{bmatrix}")}
              @

              begin{document}
              [ A =
              <<echo=F,results='asis'>>=
              bmatrix(round(matrix(rnorm(6), 2 ,3),3))
              @
              ]
              [ B =
              <<echo=F,results='asis'>>=
              bmatrix(round(matrix(abs(rnorm(120)), 12 ,10),1))
              @
              ]
              setcounter{MaxMatrixCols}{12}
              [ C =
              <<echo=F,results='asis'>>=
              bmatrix(round(matrix(abs(rnorm(144)), 12 ,12),1))
              @
              ]
              end{document}



              enter image description here







              share|improve this answer






























                2














                Matrices of normal random numbers using knitr:



                documentclass{article}
                usepackage{amsmath}

                <<bmatrix,echo=F>>=
                options(digits=2)
                bmatrix <- function(matr) {
                printmrow <- function(x) {cat(cat(x,sep=" & "),"\\ n")}
                cat("\begin{bmatrix}","n")
                body <- apply(matr,1,printmrow)
                cat("\end{bmatrix}")}
                @

                begin{document}
                [ A =
                <<echo=F,results='asis'>>=
                bmatrix(round(matrix(rnorm(6), 2 ,3),3))
                @
                ]
                [ B =
                <<echo=F,results='asis'>>=
                bmatrix(round(matrix(abs(rnorm(120)), 12 ,10),1))
                @
                ]
                setcounter{MaxMatrixCols}{12}
                [ C =
                <<echo=F,results='asis'>>=
                bmatrix(round(matrix(abs(rnorm(144)), 12 ,12),1))
                @
                ]
                end{document}



                enter image description here







                share|improve this answer




























                  2












                  2








                  2







                  Matrices of normal random numbers using knitr:



                  documentclass{article}
                  usepackage{amsmath}

                  <<bmatrix,echo=F>>=
                  options(digits=2)
                  bmatrix <- function(matr) {
                  printmrow <- function(x) {cat(cat(x,sep=" & "),"\\ n")}
                  cat("\begin{bmatrix}","n")
                  body <- apply(matr,1,printmrow)
                  cat("\end{bmatrix}")}
                  @

                  begin{document}
                  [ A =
                  <<echo=F,results='asis'>>=
                  bmatrix(round(matrix(rnorm(6), 2 ,3),3))
                  @
                  ]
                  [ B =
                  <<echo=F,results='asis'>>=
                  bmatrix(round(matrix(abs(rnorm(120)), 12 ,10),1))
                  @
                  ]
                  setcounter{MaxMatrixCols}{12}
                  [ C =
                  <<echo=F,results='asis'>>=
                  bmatrix(round(matrix(abs(rnorm(144)), 12 ,12),1))
                  @
                  ]
                  end{document}



                  enter image description here







                  share|improve this answer















                  Matrices of normal random numbers using knitr:



                  documentclass{article}
                  usepackage{amsmath}

                  <<bmatrix,echo=F>>=
                  options(digits=2)
                  bmatrix <- function(matr) {
                  printmrow <- function(x) {cat(cat(x,sep=" & "),"\\ n")}
                  cat("\begin{bmatrix}","n")
                  body <- apply(matr,1,printmrow)
                  cat("\end{bmatrix}")}
                  @

                  begin{document}
                  [ A =
                  <<echo=F,results='asis'>>=
                  bmatrix(round(matrix(rnorm(6), 2 ,3),3))
                  @
                  ]
                  [ B =
                  <<echo=F,results='asis'>>=
                  bmatrix(round(matrix(abs(rnorm(120)), 12 ,10),1))
                  @
                  ]
                  setcounter{MaxMatrixCols}{12}
                  [ C =
                  <<echo=F,results='asis'>>=
                  bmatrix(round(matrix(abs(rnorm(144)), 12 ,12),1))
                  @
                  ]
                  end{document}



                  enter image description here








                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 11 hours ago

























                  answered 12 hours ago









                  FranFran

                  52.8k6118182




                  52.8k6118182






















                      john is a new contributor. Be nice, and check out our Code of Conduct.










                      draft saved

                      draft discarded


















                      john is a new contributor. Be nice, and check out our Code of Conduct.













                      john is a new contributor. Be nice, and check out our Code of Conduct.












                      john is a new contributor. Be nice, and check out our Code of Conduct.
















                      Thanks for contributing an answer to TeX - LaTeX 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.


                      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%2ftex.stackexchange.com%2fquestions%2f477728%2fhow-do-i-construct-an-nxn-matrix%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

                      How to label and detect the document text images

                      Vallis Paradisi

                      Tabula Rosettana