如何将Scilab控制台中的矩阵以快捷方式转换为乳胶?

时间:2018-08-23 04:37:12

标签: latex scilab

实际上,我在Scilab的控制台中有一个大型矩阵。在乳胶的TeXt文件中键入此矩阵非常繁琐。我的目标是在文本文件中自动为此矩阵编写乳胶代码。有谁能够帮助我? [我有这样的大矩阵A = [0.2 0.3 0.3; 0.4 0.5 0.6; 0.7 0.8 0.9]。 (在某种意义上说,行大约运行30,列大约运行6)。

2 个答案:

答案 0 :(得分:1)

您可以简单地使用本机函数prettyprint

--> z = rand(4,4);
--> prettyprint(z)
 ans  =

 ${\begin{pmatrix}0.6733739&0.1899375&0.0403497&0.2514597\cr 0.6536 
 925&0.2583981&0.7400147&0.3843350\cr 0.1996896&0.0987874&0.6162660 
 &0.4396460\cr 0.6014125&0.0619903&0.6583583&0.6540737\cr \end{pmat 
 rix}}$  

结果有点混乱,但是您可以将其最低版本复制并粘贴到TeX文件中。例如,我必须删除关键字pmatrix中的换行符:

\documentclass{standalone}
\usepackage{amsmath}
\begin{document}

 ${\begin{pmatrix}0.6733739&0.1899375&0.0403497&0.2514597\cr 0.6536 
 925&0.2583981&0.7400147&0.3843350\cr 0.1996896&0.0987874&0.6162660 
 &0.4396460\cr 0.6014125&0.0619903&0.6583583&0.6540737\cr \end{pmatrix}}$

\end{document}

输出:

Minimum TeX output

如果矩阵的列数超过10,则需要在前导码中添加\setcounter{MaxMatrixCols}{ncols},其中ncols大于列数。

答案 1 :(得分:0)

您的问题缺少有关输入矩阵的信息:实数,复数,整数值?以及如何获得输出:浮动,指数式?

由于您的问题非常简单且不稳定,因此,这里的答案将采用一个真实矩阵:

function display_as_pmatrix(A,fmt)
  if ~exists('fmt') then // default format : 10-th wide exponential notation with 3 digit
    fmt='%10.3e'
  end
  // writing a latex pmatrix 
  // & between each term
  // \\ a the end of each row
  // except on the last row
  mprintf('\\begin{pmatrix}\n') // mprintf accept C-printf 
  for j=1:size(A,1)-1
    mprintf(fmt,A(j,1).')
    mprintf(' \& '+fmt,A(j,2:$).')
    mprintf('\\\\\n')
  end
  j=size(A,1)
  mprintf(fmt,A(j,1).')
  mprintf(' \& '+fmt,A(j,2:$).')
  mprintf('\n\\end{pmatrix}\n')
endfunction

此功能的用法如下

-->display_as_pmatrix(A,'%10.3e')
\begin{pmatrix}
 2.360e-01 &  8.837e-01 &  2.262e-02\\
 4.076e-01 &  2.393e-01 &  8.311e-01\\
 7.294e-01 &  9.087e-01 &  4.105e-01
\end{pmatrix}

-->display_as_pmatrix(A,'%5.2g')
\begin{pmatrix}
 0.24 &  0.88 & 0.23\\
 0.41 &  0.24 &  0.83\\
 0.73 &  0.91 &  0.41
\end{pmatrix}