{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This is an example of a Maxima-Jupyter notebook, showing text, formulas, and plots. To start with, I'll compute an integral." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{0}$}\\sqrt{\\pi}\\]" ], "text/plain": [ "(%o0) sqrt(%pi)" ], "text/x-maxima": [ "sqrt(%pi)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "integrate (exp(-t^2), t, minf, inf);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Terrific. How about an example that shows the nice $\\rm{\\LaTeX}$ integral sign." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{1}$}\\int_{a}^{b}{x\\,\\log x\\;dx}\\]" ], "text/plain": [ " b\n", " /\n", " [\n", "(%o1) I x log(x) dx\n", " ]\n", " /\n", " a" ], "text/x-maxima": [ "'integrate(x*log(x),x,a,b)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'integrate (x*log(x), x, a, b);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Questions from Maxima to the user (via `asksign`) cause the notebook to open an input prompt and report the input back to the Maxima kernel. In the next example, let's try the same input twice and answer the question in different ways." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ "Is k equal to - 1?\n", " y;\n" ] }, { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{2}$}\\log u\\]" ], "text/plain": [ "(%o2) log(u)" ], "text/x-maxima": [ "log(u)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "integrate (u^k, u);" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ "Is k equal to - 1?\n", " n;\n" ] }, { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{3}$}\\frac{u^{k+1}}{k+1}\\]" ], "text/plain": [ " k + 1\n", " u\n", "(%o3) ------\n", " k + 1" ], "text/x-maxima": [ "u^(k+1)/(k+1)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "integrate (u^k, u);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What about finding the roots of a polynomial?" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{4}$}\\left[ x=\\frac{2^{\\frac{1}{3}}\\,\\sqrt{3}\\,i-2^{\\frac{1}{3}}}{2} , x=-\\left(\\frac{2^{\\frac{1}{3}}\\,\\sqrt{3}\\,i+2^{\\frac{1}{3}}}{2}\\right) , x=2^{\\frac{1}{3}} \\right] \\]" ], "text/plain": [ " 1/3 1/3 1/3 1/3\n", " 2 sqrt(3) %i - 2 2 sqrt(3) %i + 2 1/3\n", "(%o4) [x = ----------------------, x = - ----------------------, x = 2 ]\n", " 2 2" ], "text/x-maxima": [ "[x = (2^(1/3)*sqrt(3)*%i-2^(1/3))/2,x = -((2^(1/3)*sqrt(3)*%i+2^(1/3))/2),\n", " x = 2^(1/3)]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "foo : solve (x^3 - 2, x);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's verify that the elements of `foo` are indeed the roots in question." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{5}$}\\left[ \\frac{\\left(2^{\\frac{1}{3}}\\,\\sqrt{3}\\,i-2^{\\frac{1}{3}}\\right)^3}{8} , -\\left(\\frac{\\left(2^{\\frac{1}{3}}\\,\\sqrt{3}\\,i+2^{\\frac{1}{3}}\\right)^3}{8}\\right) , 2 \\right] \\]" ], "text/plain": [ " 1/3 1/3 3 1/3 1/3 3\n", " (2 sqrt(3) %i - 2 ) (2 sqrt(3) %i + 2 )\n", "(%o5) [-------------------------, - -------------------------, 2]\n", " 8 8" ], "text/x-maxima": [ "[(2^(1/3)*sqrt(3)*%i-2^(1/3))^3/8,-((2^(1/3)*sqrt(3)*%i+2^(1/3))^3/8),2]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar : map (lambda ([u], u^3), map (rhs, foo));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Well, it's still not obvious. Let's simplify a little." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{6}$}\\left[ 2 , 2 , 2 \\right] \\]" ], "text/plain": [ "(%o6) [2, 2, 2]" ], "text/x-maxima": [ "[2,2,2]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map (radcan, bar);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here's a different way to simplify." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{7}$}\\left[ 2 , 2 , 2 \\right] \\]" ], "text/plain": [ "(%o7) [2, 2, 2]" ], "text/x-maxima": [ "[2,2,2]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map (expand, bar);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's make a plot. Note that in order for the results from `plot2d` to be displayed in the notebook a file name needs to specified." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "plot2d: some values will be clipped.\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "Gnuplot\n", "Produced by GNUPLOT 5.4 patchlevel 9 \n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t \n", "\t \n", "\t\n", "\t\n", "\t \n", "\t \n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\n", "\n", "\t\n", "\n", "\t\n", "\t\tx\n", "\t\n", "\n", "\n", "\n", "\tgnuplot_plot_1\n", "\n", "\t\n", "\t\tsin\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\tgnuplot_plot_2\n", "\n", "\t\n", "\t\tcos\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\tgnuplot_plot_3\n", "\n", "\t\n", "\t\ttan\n", "\t\n", "\n", "\n", "\t\t\t\n", "\t\n", "\n", "\t\t\n", "\t\t-10\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t-5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 0\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 10\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t-10\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t-5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 0\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 10\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "/tmp/maxplot.svg" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plot2d ([sin, cos, tan], [x, -10, 10], [y, -10, 10], [svg_file, \"maxplot.svg\"],[plot_format, gnuplot])$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By the way, output to standard output (e.g. the output of `print` or `describe`) is displayed in the notebook as plain text." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "HELLO WORLD!" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{9}$}\\mbox{ HELLO WORLD! }\\]" ], "text/plain": [ "(%o9) HELLO WORLD!" ], "text/x-maxima": [ "\"HELLO WORLD!\"" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print (\"HELLO WORLD!\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the case of `print`, the printed value is also returned, so it is typeset also." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "OK, that's all for now!" ] } ], "metadata": { "kernelspec": { "display_name": "Maxima", "language": "maxima", "name": "maxima" }, "language_info": { "codemirror_mode": "maxima", "file_extension": ".mac", "mimetype": "text/x-maxima", "name": "maxima", "pygments_lexer": "maxima", "version": "5.47.0" } }, "nbformat": 4, "nbformat_minor": 4 }