Skip to main content
added 529 characters in body
Source Link
kabenyuk
  • 18.2k
  • 2
  • 12
  • 28

As far as I understand, in the preamble it is sufficient to load only

\usepackage{luacas}

For your plotting fragment, you also need the pgfplots package. Then everything works. Here is a minimal example.

\documentclass{article}
\usepackage{luacas}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{CAS}
vars('x')
f = x^2+2*x-2
g = x^2-1
subs = {[x] = f}
dh = expand(substitute(subs,g))
h = simplify(int(dh,x)+10)
\end{CAS}

For\noindent
Bob Bob’sdoes purposesnot need a nicely typeset formula in the text, $\fetchsuch as
\[
\print{h}$ is.
\]
For exactlyhis whatpurpose, he needs the expression produced by
\[
\fetch{h}
\]
instead:

\medskip
\begin{center}
\begin{tikzpicture}[scale=0.9]
  \begin{axis}[legend pos = north west]
    \addplot [domain=-3.5:1.5,samples=100]
      {\fetch{h}};
    \addlegendentry{$f$$h$};
    \addplot[densely dashed]
      [domain=-3.25:1.25,samples=100]
      {\fetch{dh}};
    \addlegendentry{$df/dx$$h'$};
    \addplot[gray,dashed,thick]
      [domain=-3.5:1.5] {0};
  \end{axis}
\end{tikzpicture}
\end{center}

Here $dh$ is obtained by substituting $f$ into $g$, so $dh(x)=g(f(x))$. The function $h$ is then defined by
\[
h(x)=\int g(f(x))\,dx+10.
\]
\end{document}

enter image description hereenter image description here

Edit.
I have edited the code slightly to make the example more meaningful. The main purpose of the luacas package is to provide symbolic computations directly within LuaLaTeX.

As far as I understand, in the preamble it is sufficient to load only

\usepackage{luacas}

For your plotting fragment, you also need the pgfplots package. Then everything works. Here is a minimal example.

\documentclass{article}
\usepackage{luacas}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{CAS}
vars('x')
f = x^2+2*x-2
g = x^2-1
subs = {[x] = f}
dh = expand(substitute(subs,g))
h = simplify(int(dh,x)+10)
\end{CAS}

For Bob’s purposes, $\fetch{h}$ is exactly what he needs:

\medskip
\begin{tikzpicture}[scale=0.9]
  \begin{axis}[legend pos = north west]
    \addplot [domain=-3.5:1.5,samples=100]
      {\fetch{h}};
    \addlegendentry{$f$};
    \addplot[densely dashed]
      [domain=-3.25:1.25,samples=100]
      {\fetch{dh}};
    \addlegendentry{$df/dx$};
    \addplot[gray,dashed,thick]
      [domain=-3.5:1.5] {0};
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

As far as I understand, in the preamble it is sufficient to load only

\usepackage{luacas}

For your plotting fragment, you also need the pgfplots package. Then everything works. Here is a minimal example.

\documentclass{article}
\usepackage{luacas}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{CAS}
vars('x')
f = x^2+2*x-2
g = x^2-1
subs = {[x] = f}
dh = expand(substitute(subs,g))
h = simplify(int(dh,x)+10)
\end{CAS}

\noindent
Bob does not need a nicely typeset formula in the text, such as
\[
\print{h}.
\]
For his purpose, he needs the expression produced by
\[
\fetch{h}
\]
instead:


\begin{center}
\begin{tikzpicture}[scale=0.9]
  \begin{axis}[legend pos = north west]
    \addplot [domain=-3.5:1.5,samples=100]
      {\fetch{h}};
    \addlegendentry{$h$};
    \addplot[densely dashed]
      [domain=-3.25:1.25,samples=100]
      {\fetch{dh}};
    \addlegendentry{$h'$};
    \addplot[gray,dashed,thick]
      [domain=-3.5:1.5] {0};
  \end{axis}
\end{tikzpicture}
\end{center}

Here $dh$ is obtained by substituting $f$ into $g$, so $dh(x)=g(f(x))$. The function $h$ is then defined by
\[
h(x)=\int g(f(x))\,dx+10.
\]
\end{document}

enter image description here

Edit.
I have edited the code slightly to make the example more meaningful. The main purpose of the luacas package is to provide symbolic computations directly within LuaLaTeX.

Source Link
kabenyuk
  • 18.2k
  • 2
  • 12
  • 28

As far as I understand, in the preamble it is sufficient to load only

\usepackage{luacas}

For your plotting fragment, you also need the pgfplots package. Then everything works. Here is a minimal example.

\documentclass{article}
\usepackage{luacas}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{CAS}
vars('x')
f = x^2+2*x-2
g = x^2-1
subs = {[x] = f}
dh = expand(substitute(subs,g))
h = simplify(int(dh,x)+10)
\end{CAS}

For Bob’s purposes, $\fetch{h}$ is exactly what he needs:

\medskip
\begin{tikzpicture}[scale=0.9]
  \begin{axis}[legend pos = north west]
    \addplot [domain=-3.5:1.5,samples=100]
      {\fetch{h}};
    \addlegendentry{$f$};
    \addplot[densely dashed]
      [domain=-3.25:1.25,samples=100]
      {\fetch{dh}};
    \addlegendentry{$df/dx$};
    \addplot[gray,dashed,thick]
      [domain=-3.5:1.5] {0};
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here