Imagine you have a matrix defined as:

\matrix(nums)[matrix of nodes]
        1 & 2 \\ 
        3 & 4 \\ 
        5 & 6\\

and you want to use what's written in node 1-2 and write it in another matrix or someplace along your tikzpicture.

Is there a way to do it?

Is it possible to choose an element of a list using some technique?


You can always define a macro for the desired contents and use whenever you need it:



Next matrix 
\matrix(nums)[matrix of nodes, left delimiter=(, right delimiter=)]
{ 1 & 2\\ 3 & \myelement \\ 5 & 6\\};
has \myelement{} in position 2,2.


enter image description here


If you're mixing math and LaTeX you should consider the sagetex package which utilizes an open source computer algebra system (CAS), Sage. That CAS needs to be installed on your machine or you can access it through a free Sagemath Cloud account. Consider the following code:

N = matrix([[M[1,1],0],[0,M[0,1]]])
For the matrix $M=\sage{M}$ the element in the $(2,1)$ position is  $\sage{M[1][0]}$.
The dot product of the first two row vectors is
$\sage{M[0][0]}\cdot \sage{M[1][0]}+\sage{M[0][1]}\cdot \sage{M[1][1]}=
\sage{M[0][0]*M[1][0]+M[0][1]*M[1][1]}$. The $2 \times 2$ diagonal matrix   $N$, with 
diagonal elements $(2,2)$ and $(1,2)$ is $\sage{N}$. In that case the matrix $M*N=

The output is shown below: enter image description here

Notice: Sage refers to matrix elements starting with 0, rather than 1 hence the (1,1) element is in the (0,0) position in the matrix. You can access the math through a \sage{} command. That allows you to pick off elements as you see fit, no macro required. You can also have Sage calculate the matrix multiplication of M*N, which eliminates the possibility of mistakes. Having a CAS do the math eliminates careless mistakes and saves you from having to typeset matrices.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.