# Difference between revisions of "SageMath"

Iosonofabio (talk | contribs) m (→SageTeX) |
Iosonofabio (talk | contribs) m (Undo revision 129982 by Iosonofabio (talk)) |
||

Line 54: | Line 54: | ||

\begin{figure} | \begin{figure} | ||

\begin{center} | \begin{center} | ||

+ | \sageplot[width=\linewidth]{ptot} | ||

\end{center} | \end{center} | ||

\end{figure} | \end{figure} |

## Revision as of 15:38, 5 February 2011

Sage is a program for numerical and symbolic mathematical computation. It is meant to provide an alternative for commercial programs such as Maple, Matlab, and Mathematica. It is actually mantained in the community repository.

## Contents

## Installation

To install binaries from community repository:

# pacman -S sage-mathematics

## Usage

### Sage-Commandline

Once installed, users should be able to start the sage commandline in bash.

$ sage

Math can then be typed at this commandline.

sage: 2+2 4

Note, however, that the CLI is not very comforable for certain purposed. For instance, if you plot a function,

sage: plot(sin,(x,0,10))

this is opened in a browser window. In these cases, you can start the notebook server by

sage: notebook()

### Sage-Notebook

To start the Sage-Notebook server from bash, without going thru Sage-Commandline:

$ sage -n

The notebook will be accessable in the browser from http://localhost:8000 , and will require you to login. However, If you are only intending to run the server for personal use, and not across the internet, the login will be an annoyance.

You can instead start Sage notebook without requiring login, and have it automatically pop up in a browser.

$ BROWSER="chromium" sage -c "notebook(require_login=false,open_viewer=true)"

More detailed documentation can be read about the "notebook() command."

### Documentation

For local Documentation, one can compile it into html or even pdfs. Apparently, this needs to be executed as root (perhaps unsafely):

# sage -docbuild reference html

This builds html docs for the whole tree "reference" (which is alot; Expect many many hours). An option is to build a smaller part of the documentation tree, but you would need to know what it is you want. Until then, you might consider just browsing reference online. One place this can be found is at http://www.sagemath.org/doc/ .

## Optional additions

### SageTeX

If you have installed Texlive on your system, you may be interested in using SageTeX, a package that makes possible the inclusion of sage code in LaTeX files. Starting from version 4.6.1-3, Texlive is made aware of SageTeX automagically, and you can start using it straight away.

As a simple example, here is how you include a Sage 2D plot in your latex document (assuming you use pdfLaTeX):

- include the sagetex package in the preamble of your document with the usual

\usepackage{sagetex}

- create a sagesilent environment in which you insert your sage code:

\begin{sagesilent} dob(x) = sqrt(x^2-1)/(x * arctan(sqrt(x^2-1))) dpr(x) = sqrt(x^2-1)/(x * log( x + sqrt(x^2-1))) p1 = plot(dob,(x,1,10),color='blue') p2 = plot(dpr,(x,1,10),color='red') ptot=p1+p2 ptot.axes_labels(['$\\xi$','$\\frac{R_h}{\\max(a,b)}$']) \end{sagesilent}

- create the plot e.g. inside a float environment:

\begin{figure} \begin{center} \sageplot[width=\linewidth]{ptot} \end{center} \end{figure}

- compile your document with the following procedure:

$pdflatex <doc.tex> $sage <doc.sage> $pdflatex <doc.tex>

- you can have a look at your output document.

The full documentation of SageTeX is available on CTAN.

#### Troubleshooting

If your Texlive installation does not find the sagetex package, you can try the following procedure (do it as root, or with sudo, or use a local folder):

- Copy the files to the texmf directory:

# cp /opt/sage/local/share/texmf/tex/* /usr/share/texmf/tex/

- Refresh Texlive:

### Additional Packages

If you need to compile your own custom packages in addition to the standard ones, you might need to install aur/sage-mathematics-spkgs so that you will have the spkgs of the original packages.