%!TEX TS-program = sage \documentclass{article} \title{MTK Basic Test 01 - Sage Integration} \author{J. Simmons} \usepackage{sagetex} \setlength{\sagetexindent}{10ex} \begin{document} \maketitle % start content here \section{Test sageblock} This section tests the ability to run Python inline using the sageblock command. The sageblock command shows the Python code in the resulting document and makes the results of the Python analysis available for later reference as shown below. \begin{sageblock} x1 = 1 x2 = 1 y = x1 + x2 \end{sageblock} The above code demonstrates that $\sage{x1} + \sage{x2} = \sage{y} $. \section{Test sagesilent} This section tests the ability to run Python inline using the sagesilent command. The sagesilent command runs the Python code without displaying the source in the resulting document and makes the results of the Python analysis available for later reference as shown below. \begin{sagesilent} x3 = 2 x4 = 2 y2 = x3 + x4 \end{sagesilent} The hidden code demonstrates that $\sage{x3} + \sage{x4} = \sage{y2}$. \section{Test PyLab Integration and Plotting} This section tests the ability to use PyLab's plotting methods to create a basic plot and then include it in the document. \begin{sageblock} from numpy import * from pylab import * # define the function to evaluate def f(x): return x^2 +2*x + 3 range_begin = -5 range_end = 5 x = linspace(range_begin, range_end, 1000) clf() plot(x, f(x), 'bo') xlabel('x') ylabel('f(x)') title('Demonstration Quadratic Plot') savefig('quadratic.png') \end{sageblock} The code above calculates values for the quadratic equations $f(x) = x^2 +2x + 3$ for the integer values from $\sage{range_begin}$ to $\sage{range_end}$ and plots these values in a newly generated file quadratic.png. The LaTeX code then conditionally includes the plot as Figure~\ref{f:quad_plot}. \IfFileExists{quadratic.png}{ \begin{figure}[h!] \centering \includegraphics[scale=.60]{quadratic.png} \caption{Including a Sage generated plot} \label{f:quad_plot} \end{figure} } \section*{} This document is a work of Mach 30 and is licensed under the Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/. \end{document}