3

I would like to be able to visually write math equations in lyx and then copy them to wolfram and symbolab to compute the answer. For example I can copy

\left(-1-\lambda\right)\cdot\left(1-\lambda\right)\left(-\lambda\right)+3

into those sites and they will be able to read it and give me the answer, however they do not understand

\begin{pmatrix}1 & 0 & 1\\
0 & 0 & 1\\
-3 & 1 & 3
\end{pmatrix}\cdot\begin{pmatrix}1 & -1 & 0\\
3 & -6 & 1\\
0 & 1 & 0
\end{pmatrix}

Do you have any recommendations for how to format it so that those sites will be able to solve the question?

HanMah
  • 155
  • Welcome to TeX.SE! As your question stands, it appears to more about some other piece of software (e.g., Wolfram Alpha), and not about TeX and friends. Your posting may therefore be more suitable for a site such as mathematica.SE. Please clarify the connection of your posting to TeX and friends. – Mico Apr 03 '16 at 04:59
  • 2
    Cross-posted at http://latex-community.org/forum/viewtopic.php?f=19&t=27271. Please read http://latex-community.org/home/latex-community/94-etiquette/454-crossposts for why you should reference your other posts. – scottkosty Apr 03 '16 at 05:04
  • BTW, Wolfram Alpha will not detect a matrix multiplication, because the format of the matrices do not match for a multiplication, which requires that the number of rows of the first matrix is equal to the number of columns of the second matrix. – Heiko Oberdiek Apr 03 '16 at 07:12
  • @scottkosty Oops, I'll keep that in mind for next time. – HanMah Apr 03 '16 at 13:14
  • By the way, am I not supposed to thank the person who answered my question?

    "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”."

    – HanMah Apr 03 '16 at 13:27
  • @HanMah I believe you are correct that this is the policy. It is difficult for me also when one of my questions is answered. I also have the reaction and desire to want to thank someone beyond the mechanical clicking of the checkmark, but I think that is the policy. – scottkosty Apr 03 '16 at 17:25

1 Answers1

3

Wolfram Alpha recognizes \cdot, but it is not a full TeX parser. Example for the matrix syntax in Wolfram Alpha (Examples > Mathematics > Matrices & Linear Algebra):

{{6, -7, 10}, {0, 3, -1}, {0, 5, -7}}

The following example defines a macro \wapmatrix, which takes a nested comma separated list as matrix like the syntax for Wolfram Alpha and writes the matrix to the screen/.log file output. Also it translates the matrix to LaTeX and sets the matrix in environment pmatrix:

\documentclass{article}
\usepackage{amsmath}
\usepackage{kvsetkeys}

\makeatletter
\newif\ifwa@first@row
\newif\ifwa@first@cell@in@row
\newcommand*{\wapmatrix}[1]{%
  \toks0={\begin{pmatrix}}%
  \toks2={}%
  \wa@first@rowtrue
  \comma@parse{#1}\wa@parse@rows
  \toks0=\expandafter{\the\toks0 \end{pmatrix}}%
  \toks2=\expandafter{\expandafter{\the\toks2}}%
  \typeout{\the\toks2}%
  \the\toks0 %
}
\newcommand*{\wa@parse@rows}[1]{%
  \ifwa@first@row
    \wa@first@rowfalse
  \else
    \toks0=\expandafter{\the\toks0 \\\relax}%
    \toks2=\expandafter{\the\toks2 ,}%
  \fi
  \wa@first@cell@in@rowtrue
  \toks4={}%
  \comma@parse{#1}\wa@parse@cells@in@row
  \toks2=\expandafter{\the\toks2\expandafter{\the\toks4}}%
}
\newcommand*{\wa@parse@cells@in@row}[1]{%
  \ifwa@first@cell@in@row
    \wa@first@cell@in@rowfalse
  \else
    \toks0=\expandafter{\the\toks0 &}%
    \toks4=\expandafter{\the\toks4 ,}%
  \fi
  \toks0=\expandafter{\the\toks0 #1}%
  \toks4=\expandafter{\the\toks4 #1}%
}

\newcommand*{\wacdot}{%
  \typeout{\string\cdot}%
  \cdot
}

\begin{document}
\[
  \typeout{--- WA begin ---}
  \wapmatrix{
    {0, 0, 1},
    {-3, 1, 3},
    {1, 2, 3}
  }%
  \wacdot
  \wapmatrix{
    {3, -6, 1},
    {0, 1, 0},
    {1, 2, 3}
  }
  \typeout{--- WA end ---}
\]
\end{document}

Result

Screen/.log file:

--- WA begin ---
{{0,0,1},{-3,1,3},{1,2,3}}
\cdot
{{3,-6,1},{0,1,0},{1,2,3}}
--- WA end ---

Then the text between the markers can be cut & pasted as query for Wolfram Alpha:

Copyable plaintext:

(1 | 2 | 3
-6 | 25 | 6
6 | 2 | 10)

Wolfram Language plaintext output:

{{1, 2, 3}, {-6, 25, 6}, {6, 2, 10}}

Then it can be copied back to the LaTeX file:

  \typeout{--- WA end ---}
  =
  \wapmatrix{{1, 2, 3}, {-6, 25, 6}, {6, 2, 10}}
\]

Result

Heiko Oberdiek
  • 271,626