Last active
December 18, 2015 05:58
-
-
Save tonussi/5736114 to your computer and use it in GitHub Desktop.
Metodo Java para formatar matrizes em latex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Formatex { | |
public static void formatMatrix(int[][] inputArray2D) { | |
assert (inputArray2D.length == inputArray2D[0].length && inputArray2D != null) : "BadInputArrayException"; | |
StringBuilder latex = new StringBuilder( | |
"\\mathbf{G}_x = \\begin{bmatrix} "); | |
for (int i = 0; i < inputArray2D.length; i++) { | |
for (int j = 0; j < inputArray2D[i].length; j++) { | |
latex.append(inputArray2D[i][j]); | |
if (j != inputArray2D[i].length - 1) | |
latex.append(" & "); | |
// if (inputArray2D[i][j] < 0) | |
// out.print(" " + inputArray2D[i][j] + " "); | |
// else | |
// out.print(" " + inputArray2D[i][j] + " "); | |
} | |
if (i != inputArray2D.length - 1) | |
latex.append(" \\\\ "); | |
latex.append(" "); | |
} | |
latex.append("\\end{bmatrix}"); | |
out.println(latex); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\mathbf{G}_x = \begin{bmatrix} 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 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 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& 2 \\ 0 & 0 & 0 & 0 & 2 & 4 & 0 & 4 \\ 0 & 0 & 0 & 0 & 0 & 2 & 4 & 0 \end{bmatrix} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment