CoCalc Shared Filesmaxima-plot-in-sagews.sagews
Author: Samuel Lelièvre
Views : 12
Description: ## Maxima plots in CoCalc .sagews worksheets

# Maxima plots in CoCalc's .sagews worksheets

• Author: Samuel Lelièvre
• Date: 2020-03-25

## Use cell magic to set the worksheet to Maxima mode

The first thing to do is to use the %default_mode magic to set the whole worksheet to Maxima mode.

(Note: it's important to put this magic in its own cell.)

%default_mode maxima


We can now use Maxima syntax.

cos(%pi/6)

sqrt(3)/2
trigsimp(2*cos(x)^2 + sin(x)^2)

cos(x)^2+1
integrate(log(x), x)

x*log(x)-x

### Avoid Maxima names starting in % at the start of a line

In IPython, in Jupyter and in CoCalc worksheets, names that starts with % at the start of a line are interpreted as "magics", so Maxima names starting in % can't be used at the start of a line.

As a workaround, add a space in front of such names, e.g. a space before %pi and %e for the mathematical constants $\pi$ and $e$.

 %pi

%pi
 %e

%e
 %pi, numer

3.141592653589793
 %e, numer

2.718281828459045

## Maxima plots

Problem reported at

loesung: rk(t-x^2, x, 1, [t, 0, 8, 0.1])$ plot2d([discrete, loesung])$

Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1234, in execute flags=compile_flags), namespace, locals) File "", line 1, in <module> File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1318, in execute_with_code_decorators code, locals=self.namespace)) # removed , end=' ' File "/ext/sage/sage-8.3_1804/local/lib/python2.7/site-packages/sage/interfaces/expect.py", line 1361, in eval raise TypeError('error evaluating "%s":\n%s'%(code,s)) TypeError: error evaluating "plot2d([discrete, loesung])": Error executing code in Maxima CODE: plot2d([discrete, loesung]); Maxima ERROR: Maxima encountered a Lisp error: Filesystem error with pathname "/home/user/.sage/temp/project-fc94de41-6af4-4ee1-a684-c33a9e56b2b0/279/ecl/maxout471.gnuplot_pipes". Either 1) the file does not exist, or 2) we are not allowed to access the file, or 3) the pathname points to a broken symbolic link. Automatically continuing. To enable the Lisp debugger set *debugger-hook* to nil.