{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "**Note**: This is taken from the [Maxima Tutorial](http://maxima.sourceforge.net/docs/tutorial/en/gaertner-tutorial-revision/Contents.htm), specifically [this page](http://maxima.sourceforge.net/docs/tutorial/en/gaertner-tutorial-revision/Pages/Intro0001.htm). Same licensing applies.\n", "\n", "# A First Look at Maxima\n", "\n", "Maxima can be used as a powerful calucator:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{2}$}2439\\]" ], "text/plain": [ "(%o2) 2439" ], "text/x-maxima": [ "2439" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "144*17 - 9;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Maxima can compute with very large numbers. The following expample computes the 25th power of 144:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{3}$}910043815000214977332758527534256632492715260325658624\\]" ], "text/plain": [ "(%o3) 910043815000214977332758527534256632492715260325658624" ], "text/x-maxima": [ "910043815000214977332758527534256632492715260325658624" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "144^25;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is more than a pocket calculator can do!\n", "\n", "Now we compute the 25th root of that result:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{4}$}144\\]" ], "text/plain": [ "(%o4) 144" ], "text/x-maxima": [ "144" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ " %^(1/25);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The percent sign is a special variable, its value is always the last result. The arrow is the exponentiation operator. In our input we used some elementary mathematical knowledge: we wrote the root as a power with a fractional exponent.\n", "\n", "But computer algebra is more than just computation with numbers. It is computation with symbols.\n", "\n", "Let us play with a polynomial in two variables:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{5}$}\\left(2\\,y+x\\right)^4\\]" ], "text/plain": [ " 4\n", "(%o5) (2 y + x)" ], "text/x-maxima": [ "(2*y+x)^4" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(x + 2*y)^4;" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{6}$}16\\,y^4+32\\,x\\,y^3+24\\,x^2\\,y^2+8\\,x^3\\,y+x^4\\]" ], "text/plain": [ " 4 3 2 2 3 4\n", "(%o6) 16 y + 32 x y + 24 x y + 8 x y + x" ], "text/x-maxima": [ "16*y^4+32*x*y^3+24*x^2*y^2+8*x^3*y+x^4" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "expand(%);" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{7}$}\\left(2\\,y+x\\right)^4\\]" ], "text/plain": [ " 4\n", "(%o7) (2 y + x)" ], "text/x-maxima": [ "(2*y+x)^4" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor(%);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Maxima can compute derivatives:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{8}$}\\cos ^2x-\\sin ^2x\\]" ], "text/plain": [ " 2 2\n", "(%o8) cos (x) - sin (x)" ], "text/x-maxima": [ "cos(x)^2-sin(x)^2" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "diff(sin(x)*cos(x), x);" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{9}$}2\\,\\cos ^2x-1\\]" ], "text/plain": [ " 2\n", "(%o9) 2 cos (x) - 1" ], "text/x-maxima": [ "2*cos(x)^2-1" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "trigsimp(%);" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{10}$}-4\\,\\cos x\\,\\sin x\\]" ], "text/plain": [ "(%o10) - 4 cos(x) sin(x)" ], "text/x-maxima": [ "-4*cos(x)*sin(x)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "diff(%, x);" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{11}$}-4\\,\\cos x\\,\\sin x\\]" ], "text/plain": [ "(%o11) - 4 cos(x) sin(x)" ], "text/x-maxima": [ "-4*cos(x)*sin(x)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "diff(sin(x)*cos(x), x, 2);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Maxima can rewrite trigonometric expressions in a canonical form, namely as finite Fourier sums:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{12}$}\\frac{\\sin \\left(5\\,x\\right)-5\\,\\sin \\left(3\\,x\\right)+10\\,\\sin x}{16}\\]" ], "text/plain": [ " sin(5 x) - 5 sin(3 x) + 10 sin(x)\n", "(%o12) ---------------------------------\n", " 16" ], "text/x-maxima": [ "(sin(5*x)-5*sin(3*x)+10*sin(x))/16" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "trigreduce (sin(x)^5);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Maxima can compute indefinite integrals:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{13}$}-\\frac{\\log \\left(x^2+2\\,x+4\\right)}{8}+\\frac{\\arctan \\left(\\frac{2\\,x+2}{2\\,\\sqrt{3}}\\right)}{4\\,\\sqrt{3}}+\\frac{\\log \\left(x-2\\right)}{4}\\]" ], "text/plain": [ " 2 x + 2\n", " 2 atan(---------)\n", " log(x + 2 x + 4) 2 sqrt(3) log(x - 2)\n", "(%o13) (- -----------------) + --------------- + ----------\n", " 8 4 sqrt(3) 4" ], "text/x-maxima": [ "(-log(x^2+2*x+4)/8)+atan((2*x+2)/(2*sqrt(3)))/(4*sqrt(3))+log(x-2)/4" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ " integrate((x + 1)/(x^3 - 8), x);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is a longer example that shows that Maxima can compute quite complicated integrals and can also often reconstruct the given integrand:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{14}$}\\left[ m>4 \\right] \\]" ], "text/plain": [ "(%o14) [m > 4]" ], "text/x-maxima": [ "[m > 4]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "assume(m>4);" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{15}$}\\frac{b^3\\,x^{m+4}}{m+4}+\\frac{3\\,a\\,b^2\\,x^{m+3}}{m+3}+\\frac{3\\,a^2\\,b\\,x^{m+2}}{m+2}+\\frac{a^3\\,x^{m+1}}{m+1}\\]" ], "text/plain": [ " 3 m + 4 2 m + 3 2 m + 2 3 m + 1\n", " b x 3 a b x 3 a b x a x\n", "(%o15) --------- + ------------- + ------------- + ---------\n", " m + 4 m + 3 m + 2 m + 1" ], "text/x-maxima": [ "(b^3*x^(m+4))/(m+4)+(3*a*b^2*x^(m+3))/(m+3)+(3*a^2*b*x^(m+2))/(m+2)\n", " +(a^3*x^(m+1))/(m+1)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "integrate(x^m*(a + b*x)^3, x);" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{16}$}b^3\\,x^{m+3}+3\\,a\\,b^2\\,x^{m+2}+3\\,a^2\\,b\\,x^{m+1}+a^3\\,x^{m}\\]" ], "text/plain": [ " 3 m + 3 2 m + 2 2 m + 1 3 m\n", "(%o16) b x + 3 a b x + 3 a b x + a x" ], "text/x-maxima": [ "b^3*x^(m+3)+3*a*b^2*x^(m+2)+3*a^2*b*x^(m+1)+a^3*x^m" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "diff(%, x);" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{17}$}x^{m}\\,\\left(b\\,x+a\\right)^3\\]" ], "text/plain": [ " m 3\n", "(%o17) x (b x + a)" ], "text/x-maxima": [ "x^m*(b*x+a)^3" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor(%);" ] } ], "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.43.0" } }, "nbformat": 4, "nbformat_minor": 2 }