如何提取元素?

如何提取元素?

我無法找到以下問題的正確答案:

(a_{1},a_{2},...,a_{n})例如,如果我們有有限向量,如何從中提取任何元素a_{5}

更清楚地說,我需要mathematica中的列表的類似物,其中我們有list={1,5,8,6,9}和list[3]=8,list[5]=9。

向量是一個數學術語,表示一個物件包含許多不同的資訊。

例如取一個程式碼

\documentclass{article}
\usepackage{tikz}
\makeatletter
\newcommand{\gettikzxy}[3]{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \edef#2{\the\pgf@x}%
  \edef#3{\the\pgf@y}%
}
\makeatother
\begin{document}
\begin{tikzpicture}
\def \A {(1,1)};
\draw \A -- (8,8);
\gettikzxy{\A}{\ax}{\ay}
\def \A {(1,1)};
\draw (\ax+10cm,\ay-5) -- (8,8);
\end{tikzpicture}
\end{document}

它“從 A 點提取坐標”並讓我對其進行操作,但我需要更通用的形式,以處理更多“元素”。

答案1

這就是該listofitems套件的作用,即使使用您要求的語法也是如此。清單分隔符號也可以更改(預設逗號)。列表的元素,例如\mylist[4],是完全可擴展的(兩次擴展將檢索列表元素的標記)。

\documentclass{article}
\usepackage{listofitems}
\begin{document}
\readlist\mylist{1,5,8,6,9}
The third element is \mylist[3] and the 5th element is \mylist[5].
\end{document}

在此輸入影像描述

相關內容