\chapter{Introduction to wxMaxima}

%%---------------------------------------------------------------------------%
\section*{Basic terms}
\addcontentsline{toc}{section}{Basic terms}

wxMaxima is a document based interface for the computer algebra system Maxima.
wxMaxima provides menus and dialogs for many common maxima commands, autocompletion,
inline plots and simple animations. wxMaxima is distributed under the GPL license.

xMaxima is a graphical interface for Maxima, written in Tcl/Tk. 
It also provides the Open Source plotting program for Maxima, 
which can do some of the plots done by Maxima's default plotter (gnuplot) 
and a few more that gnuplot cannot do. 

Maxima is one of the Open Source programs with open source code.
The program can be compiled in various OS, including Windows, GNU/Linux and MacOS~X.
A precompiled program for GNU/Linux and Windows is available free of charge
on the SourceForge website
\href{https://sourceforge.net/projects/maxima/files/}{\tt https://sour ceforge.net/projects/maxima/files/}.


After starting the wxMaxima environment, a menu window will appear on the screen at the top.
Below the menu is a space where we can enter commands and where outputs appear.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	First input line.
$\maximao1$	@\color{farbaV}First output line.@
$\maximai2$	Second input line.
$\maximao2$	@\color{farbaV}Second output line.@

\end{lstlisting}
%------------------------------------------------



We enter commands on separate lines (input lines), their execution is ensured
by simultaneously pressing the \ffbox|Shift| keys and \ffbox|Enter| or by clicking on in the menu
icon~~\tikz{\draw[very thin,black,fill=green,scale=.2] 
  (0,1em)--(1.5em,1em)--(1.5em,0)--(4em,2em)--(1.5em,4em)--(1.5em,3em)--(0,3em)--cycle;}
(Send the current cell to maxima).
Input lines are listed with $\maximaitext1$ and output lines are listed with $\maximaotext1$.
The numbers for the input line and the corresponding output line are identical
and based on this number, we can refer to the content of these lines.



%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	solve(0=x+2,x);
$\maximao1$	$\color{farbaV}[x=-2]$
$\maximai2$	%i1;
$\maximao2$	$\color{farbaV}\text{solve}(0=x+2,x)$
$\maximai3$	%o1;
$\maximao3$	$\color{farbaV}[x=-2]$
\end{lstlisting}
%------------------------------------------------



The commands are executed on new separate lines (output lines).
Commands on input lines can be terminated with the symbol~\ffB\verb|;|\ffE{} 
(which the system will automatically complete)
or the~\ffB\verb|$|\ffE{} symbol, which suppresses the display of the corresponding output.

We can enter more commands on the input line, but we must separate them
symbols~\ffB\verb|;|\ffE{} or~\ffB\verb|$|\ffE.
We can also structure the command on multiple input lines.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	a:2;b:3;solve(a*x+b*x^2=0,x)
$\maximax{(a)}$	$\color{farbaV}2$
$\maximax{(b)}$	$\color{farbaV}3$
$\maximao1$	$\color{farbaV}[x=-\frac23,x=0]$
$\maximai2$	a:2$\rbDolar$  b:3$\rbDolar$  solve(a*x+b*x^2=0,x);
$\maximao2$	$\color{farbaV}[x=-\smash{\frac23},x=0]$
$\maximai3$	a:2$\rbDolar$ 
	b:3$\rbDolar$ 
	solve(a*x+b*x^2=0,x);
$\maximao3$	$\color{farbaV}[x=-\frac23,x=0]$
\end{lstlisting}
%------------------------------------------------



We can save the output in various shapes and then use it in other programs
(\LaTeX{}, MSWord equation editor,~\dots).
Output $\maximaotext3$ from the previous window we can:

\nopagebreak[4]
\beaLOPTA
copy \ffbox|Ctrl C| and \ffbox|Ctrl V|, respectively
copy as text (can be used eg. for MSWord equation editor):
\ffB\verb|x=-2/3,x=0|\ffE,


\beaLOPTA copy as \LaTeX{}~\ffB\verb|\[x=-\frac{2}{3}\operatorname{,}x=0\]|\ffE,

\beaLOPTA copy as MathML, image, RTF, SVG\dots

The wxMaxima environment has a well-designed user help, which can be found in the  \ffbox|Hel\smash{p}| menu.
You can also open Help by pressing the~\ffbox|F1| key.
The manual can be also find on the website
\href{https://maxima.sourceforge.io/docs/manual/maxima_369.html}{\tt https://maxima.sourceforge.io/docs/manual/maxima\_369.html}.





%%---------------------------------------------------------------------------%
\section*{Basic Commands}
\addcontentsline{toc}{section}{Basic commands}


The command \ffB\verb|apropos|\ffE{} we can find out the exact name of the command using part of its name.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	apropos("plot")
$\maximao1$	@\color{farbaV}[\it barsplot,boxplot,contour\_plot,get\_plot\_option,gnuplot,\dots@
\end{lstlisting}
%------------------------------------------------


Command \ffB\verb|describe|\ffE{} prints a description of the entered command.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	describe(plot2d);
	@\color{farbaV}-\,- Function: plot2d@
	@\color{farbaV}plot2d (<expr><,<range\_x><,<options><)@
	@\color{farbaV}plot2d (<expr\_<>=<expr\_<>,<range\_x><,<range\_y><,<options><)@
	@\color{farbaV}plot2d ([parametric,<expr\_x><,<expr><\_y,<range><],<options><)@
	@\color{farbaV}plot2d ([discrete,<points><],<options><)@
	@\color{farbaV}plot2d ([contour,<expr><],<range\_x><,<range\_y><,<options><)@
	@\color{farbaV}plot2d ([<type\_<>,...,<type\_n><],<options><)@
	@\color{farbaV}There are 5 types of plots that can be plotted by 'plot2d':@
		@\color{farbaV}1. Explicit functions.  'plot2d' ...@
	@\color{farbaV}\dots@
$\maximao1$	@\it\color{farbaV}true@
\end{lstlisting}
%------------------------------------------------




Expressions are entered using the usual characters of operations, sessions and functions.
Arguments of functions and commands are in parentheses, multiplication symbol~\ffB\verb|*|\ffE{}
must be entered!
The exponentiation is specified by the character~\ffB\verb|^|\ffE{} or the pair~\ffB\verb|**|\ffE{}.

Symbol~\ffB\verb|:|\ffE{} is used to assign a value to the right of the expression to the left.
The following commands solve the equation $2x+3x^2=0$ with unknown variable~$x$.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	a:2$\rbDolar$  b:3$\rbDolar$  solve(a*x+b*x^2=0,x);
$\maximao1$	$\color{farbaV}[x=-\frac23,x=0]$                           
\end{lstlisting}
%------------------------------------------------





In the menu~\ffbox|View| and submenu~\ffbox|Dis\smash{p}la\smash{y} e\smash{q}uations| we can change
display output lines
for shapes~\ffbox|in 2D|, \ffbox|as 1D ASCII| or \ffbox|as ASCII Art|.

The default display is~\ffbox|in 2D|.
You can also change the output settings with the command \ffB\verb|set_display|\ffE.
Setting to shape~\ffbox|in 2D| has argument~\ffB\verb|none|\ffE.

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	x/sqrt(x^2+1);set_display('none)$\rbDolar$
$\maximao1$	$\color{farbaV}\smash{\frac{x}{\sqrt{{{x}^{2}}+1}}}$			/* in 2D */
\end{lstlisting}
%------------------------------------------------



Using the~\ffB\verb|ascii|\ffE{} argument command \ffB\verb|set_display|\ffE{} 
change the display output to the form \ffbox|as 1D ASCII|
and using the~\ffB\verb|xml|\ffE{} argument to form~\ffbox|as ASCII Art|.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	x/sqrt(x^2+1);set_display('ascii)$\rbDolar$
$\maximao1$	$\color{farbaV}x/\text{sqrt}(x^2+1)$			/* as 1D ASCII */
$\maximai2$	x/sqrt(x^2+1);set_display('xml)$\rbDolar$
	     @\color{farbaV}x@
$\maximao2$	@\color{farbaV}-\,-\,-\,-\,-\,-\,-\,-\,-@	/* as ASCII Art */
	      @\color{farbaV}2@
	@\color{farbaV}sqrt(x  + 1)@
\end{lstlisting}
%------------------------------------------------




With the \ffB\verb|kill|\ffE{} command 
we can remove variables with all their assignments and properties from memory.

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	kill(a,b)	/* removes all bindings from the arguments a,b */
$\maximai2$	kill(all)	/* removes all items on all infolists */
\end{lstlisting}
%------------------------------------------------




%%---------------------------------------------------------------------------%
\section*{Working with Numbers and Basic Constants}
\addcontentsline{toc}{section}{Working with numbers and basic constants}


Maxima can work with real numbers written in numerical or symbolic form.
The way of writing real numbers can be set in the menu~\ffbox|Numeric| using the switch
\ffbox|Numeric Out\smash{p}ut| between numeric and symbolic display.
Here we can also choose the method and accuracy of numerical display.
The setting of the variable~\ffB\verb|numer|\ffE{} determines the method of displaying.

By default, 16 digits (including the decimal point) are displayed.
The display accuracy is defined by the variable~\ffB\verb|fpproc|\ffE{} 
and affects the display using \ffB\verb|bfloat|\ffE.
Output~\ffB\verb|float|\ffE{} always displays the same.
We can increase or decrease the accuracy practically indefinitely.
We can change it globally and locally for only one variable or command.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	log(2);
$\maximao1$	$\color{farbaV}\log(2)$
$\maximai2$	log(2),numer;
$\maximao2$	$\color{farbaV}0.6931471805599453$
$\maximai3$	float(log(2));
$\maximao3$	$\color{farbaV}0.6931471805599453$
$\maximai4$	bfloat(log(2));
$\maximao4$	$\color{farbaV}6.931471805599453b-1$
$\maximai5$	log(2),bfloat;
$\maximao5$	$\color{farbaV}6.931471805599453b-1$
$\maximai6$	bfloat(log(2)),fpprec=34;
$\maximao6$	$\color{farbaV}6.931471805599453094172321214581766b-1$
$\maximai6$	bfloat(log(2)),fpprec=134;
$\maximao6$	@\color{farbaV}$6.9314718055994530941723212145${\color{black!50}[\!{\it78digits}]}$102057068573368552023575813b-1$@
\end{lstlisting}
%------------------------------------------------




Numeric constants $\ee$, $\pi$, $\ii$ (imaginary unit)
have the prefix~\ffB\verb|%|\ffE, i.e.~\ffB\verb|%e|\ffE, \ffB\verb|%pi|\ffE, \ffB\verb|%i|\ffE{}.
This also applies to constants that are part of or the result of calculations.
They also have the prefix~\ffB\verb|%|\ffE{}.

Maxima has predefined constants~\ffB\verb|inf|\ffE, \ffB\verb|minf|\ffE{} for real infinite $\infty$, $-\infty$
and \ffB\verb|infinity|\ffE{} for complex infinity.

Logical constants~\ffB\verb|true|\ffE{} and \ffB\verb|false|\ffE{} they represent truth and untruth.

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	%pi+%i+%e;
$\maximao1$	$\color{farbaV}\pi+\%\ii+\%\ee$ 
$\maximai2$	[minf,inf]; 
$\maximao2$	$\color{farbaV}[-\infty,\infty]$  
$\maximai3$	infinity; 
$\maximao3$	@\it\color{farbaV}infinity@
\end{lstlisting}
%------------------------------------------------




We do not deal with complex numbers in this course, so we will only mention how they are displayed.
By default, complex numbers are entered in algebraic form (\ffB\verb|rectform|\ffE).
They can be converted to trigonometric (exponential) form using the command \ffB\verb|polarform|\ffE.

%------------------------------------------------
\begin{lstlisting}[lineskip=.25em]
$\maximai1$	z:1+%i;
$\maximax{(z)}$	$\color{farbaV}\ii+1$
$\maximai2$	polarform(z)+rectform(z);
$\maximao2$	$\color{farbaV}\sqrt2\ee^{\frac{\ii\pi}{4}}+\ii+1$
\end{lstlisting}
%------------------------------------------------


%%---------------------------------------------------------------------------%
\section*{Assignments and Functions}
\addcontentsline{toc}{section}{Assignments and Functions}

The~\ffB\verb|:|\ffE{} operator we use to assign values or expressions to variables.
We define functions using the assignment~\ffB\verb|:=|\ffE.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	f(x):=x^2+2*x+3;
$\maximao1$	$\color{farbaV}f(x):=x^2+2x+3$
$\maximai6$	f(x);f(y);f(x+1);f(-2);f(1);
$\maximao2$	$\color{farbaV}x^2+2x+3$
$\maximao3$	$\color{farbaV}y^2+2y+3$
$\maximao4$	$\color{farbaV}(x+1)^2+2(x+1)+3$
$\maximao5$	$\color{farbaV}3$
$\maximao6$	$\color{farbaV}6$
\end{lstlisting}
%------------------------------------------------




Maxima contains many more functions than standard programming languages.
These are not only the real functions themselves, but also various functions for their support.
The basic functions include
\ffB\verb|sign(x)|\ffE,
\ffB\verb|abs(x)|\ffE,
\ffB\verb|floor(x)|\ffE{} (bottom whole of $x$)
\ffB\verb|round(x)|\ffE{} (rounded $x$ to the nearest whole number),
\ffB\verb|truncate(x)|\ffE{} (removes all digits after the decimal point),
\ffB\verb|ceiling(x)|\ffE{} (upper integer $x$).


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai2$	f(x):=sign(x)$\rbDolar$
		print(f(-3.6),f(-3.2),f(-3),f(0),f(3),f(3.2),f(3.6))$\rbDolar$
	@\it\color{farbaV}neg neg neg zero pos pos pos@
$\maximai4$	f(x):=abs(x)$\rbDolar$
		print(f(-3.6),f(-3.2),f(-3),f(0),f(3),f(3.2),f(3.6))$\rbDolar$
	@\color{farbaV}$3.6$ $3.2$ $3$ $0$ $3$ $3.2$ $3.6$@
$\maximai6$	f(x):=floor(x)$\rbDolar$ 
		print(f(-3.6),f(-3.2),f(-3),f(0),f(3),f(3.2),f(3.6))$\rbDolar$
	@\color{farbaV}$-4$ $-4$ $-3$ $0$ $3$ $3$ $3$@
$\maximai8$	f(x):=round(x)$\rbDolar$ 
		print(f(-3.6),f(-3.2),f(-3),f(0),f(3),f(3.2),f(3.6))$\rbDolar$
	@\color{farbaV}$-4$ $-3$ $-3$ $0$ $3$ $3$ $4$@
$\maximai{10}$	f(x):=truncate(x)$\rbDolar$ 
		print(f(-3.6),f(-3.2),f(-3),f(0),f(3),f(3.2),f(3.6))$\rbDolar$
	@\color{farbaV}$-3$ $-3$ $-3$ $0$ $3$ $3$ $3$@
$\maximai{12}$	f(x):=ceiling(x)$\rbDolar$ 
		print(f(-3.6),f(-3.2),f(-3),f(0),f(3),f(3.2),f(3.6))$\rbDolar$
	@\color{farbaV}$-3$ $-3$ $-3$ $0$ $3$ $4$ $4$@
\end{lstlisting}
%------------------------------------------------





We used the command \ffB\verb|print|\ffE{} to format the report.

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai3$	a:2$\rbDolar$ b:log(2),numer$\rbDolar$ 
		print("Logarithm of a number",a," is ",log(a),"=",b)$\rbDolar$                                    
	@\color{farbaV}Logarithm of a number 2 is $\log{(2)}=0.6931471805599453$@
\end{lstlisting}
%------------------------------------------------



Maxima contains many elementary functions.
They are, for example
\ffB\verb|exp(x)=%e^x|\ffE,
\ffB\verb|log(x)|\ffE,
trigonometric functions, their inverse functions
\ffB\verb|sin(x)|\ffE{} and
\ffB\verb|asin(x)|\ffE,
\ffB\verb|cos(x)|\ffE{} and
\ffB\verb|acos(x)|\ffE,
\ffB\verb|tan(x)|\ffE{} and
\ffB\verb|atan(x)|\ffE,
\ffB\verb|cot(x)|\ffE{} and 
\ffB\verb|acot(x)|\ffE,
hyperbolic functions and their inverse functions
\ffB\verb|sinh(x)|\ffE{} and
\ffB\verb|asinh(x)|\ffE,
\ffB\verb|cosh(x)|\ffE{} and
\ffB\verb|acosh(x)|\ffE,
\ffB\verb|tanh(x)|\ffE{} and
\ffB\verb|atanh(x)|\ffE,
\ffB\verb|coth(x)|\ffE{} and
\ffB\verb|acoth(x)|\ffE~etc.




Maxima also includes many features to support them.
Some of them are not implemented directly in the wxMaxima environment, but in external libraries
called packages.
These packages are loaded into the system using the \ffB\verb|load|\ffE{} command.
We will show the \ffB\verb|spangl|\ffE{} package for an example to support work with trigonometric functions.


%------------------------------------------------
\begin{lstlisting}[lineskip=.65em]
$\maximai2$	print(tan(%pi/8), ratsimp(tan(%pi/8)), trigsimp(tan(%pi/8)))$\rbDolar$
	@\color{farbaV}$\tan{(\frac{\pi}{8})}$ $\tan{(\frac{\pi}{8})}$ $\smash{\frac{\sin{(\frac{\pi}{8})}}{\cos{(\frac{\pi}{8})}}}$@
$\maximai3$	load(spangl);
$\maximao3$	@\it\color{farbaV}../share/trigonometry/spangl.mac@
$\maximai4$	tan(%pi/8);
$\maximao4$	$\color{farbaV}\sqrt2-1$
\end{lstlisting}
%------------------------------------------------



%%---------------------------------------------------------------------------%
\section*{Working with Expressions}
\addcontentsline{toc}{section}{Working with Expressions}

Maxima operations and calculations take place in an environment,
in which the system presupposes the validity of certain conditions.
We may change these terms.
Many times we need to change the conditions only locally for a particular calculation without
to change global settings.
For this purpose, Maxima has a very efficient~\ffB\verb|ev|\ffE{} command that allows
define a specific environment within a single command.

After entering the command \ffB\verb|ev(a,b1,b2,..., bn)|\ffE{}
the expression~\ffB\verb|a|\ffE{} is evaluated if the 
conditions~\ffB\verb|b1|\ffE, 
\ffB\verb|b2|\ffE,~\dots, 
\ffB\verb|bn|\ffE{} are met.
These conditions can be equations, assignments, functions, switches (logical settings).
The example shows an example of solving a quadratic equation using the command 
\ffB\verb|solve|\ffE.
Variables~\ffB\verb|a|\ffE, \ffB\verb|b|\ffE, \ffB\verb|c|\ffE{} after executing the command \ffB\verb|ev|\ffE{} 
they do not have values assigned.


%------------------------------------------------
\begin{lstlisting}[lineskip=.25em]
$\maximai1$	ev(solve(a*x^2+b*x+c=0,x),a:2,b:-1,c=-3);
$\maximao1$	$\color{farbaV}[x=\frac32,x=-1]$
$\maximai2$	solve(a*x^2+b*x+c=0,x);
$\maximao2$	$\color{farbaV}\smash{\big[x=-\frac{\sqrt{b^2-4ac}+b}{2a},x=\frac{\sqrt{b^2-4ac}-b}{2a}\big]}$
\end{lstlisting}
%------------------------------------------------



Maxima offers several commands for simplifying and editing various expressions.
The basic functions can be found in the \ffbox|Sim\smash{p}lif\smash{y}| menu.
With the \ffB\verb|ratsimp|\ffE{} commands and \ffB\verb|trigsimp|\ffE{} we have already met
and when adjusting the value of \ffB\verb|tan(%pi/8)|\ffE{} they did not have the desired effect.

Maxima offers using the \ffB\verb|example|\ffE{} command examples of individual commands.
Let's take a look at some of the examples offered by \ffB\verb|example(ratsimp)|\ffE.

%------------------------------------------------
\begin{lstlisting}[lineskip=.3em]
$\maximai2$	f(x):=b*(a/b-x)+b*x+a$\rbDolar$ print(f(x),"?",ratsimp(f(x)))$\rbDolar$
	$\color{farbaV}bx+b(\frac{a}{b}-x)+a$ $\color{farbaV}?$ $\color{farbaV}2a$
$\maximai3$	ratsimp(a+1/a);
$\maximao3$	$\color{farbaV}\frac{a^2+1}{a}$
$\maximai4$	ev(x^(a+1/a),ratsimp);
$\maximao4$	$\color{farbaV}x^{a+\frac1a}$
$\maximai5$	ev(x^(a+1/a),ratsimpexpons);
$\maximao5$	$\color{farbaV}\smash{x^{\frac{a^2+1}{a}}}$ 
\end{lstlisting}
%------------------------------------------------



Function~\ffB\verb|expand|\ffE{} multiplies the relevant members in the expression.

Function~\ffB\verb|factor|\ffE{} on the contrary, it decomposes the expression.

Function~\ffB\verb|gfactor|\ffE{} it does so over a field of complex numbers.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	f(x):=(x+1)*(x^2-4)*(x^2+4)$\rbDolar$
$\maximai3$	ratsimp(f(x));expand(f(x));
$\maximao2$	$\color{farbaV}x^5+x^4-16x-16$
$\maximao3$	$\color{farbaV}x^5+x^4-16x-16$
$\maximai6$	factor(f(x));gfactor(f(x));factor(100);
$\maximao4$	$\color{farbaV}(x-2)(x+1)(x+2)(x^2+4)$
$\maximao5$	$\color{farbaV}(x-2)(x+1)(x+2)(x-2\%\ii)(x+2\%\ii)$
$\maximao6$	$\color{farbaV}2^25^2$
\end{lstlisting}
%------------------------------------------------





We decompose a rational polynomial function into partial fractions using 
the command \ffB\verb|partfrac|\ffE.

%------------------------------------------------
\begin{lstlisting}[lineskip=.25em]
$\maximai1$	partfrac((x+1)/(x^2-2*x+1),x);
$\maximao1$	$\color{farbaV}\frac{1}{x-1}+\smash{\frac{2}{(x-1)^2}}$
\end{lstlisting}
%------------------------------------------------




We can substitute expressions using the commands~\ffB\verb|subst(a,b,c)|\ffE{} and \ffB\verb|ratsubst(a,b,c)|\ffE.
The expression~\ffB\verb|a|\ffE{} will be replaced by~\ffB\verb|b|\ffE{} and subsequently 
substituted into the expression~\ffB\verb|c|\ffE.
When using the \ffB\verb|subst|\ffE{} command must be~\ffB\verb|b|\ffE{} the simplest part (atom) or
a complete subexpression of the expression~\ffB\verb|c|\ffE.
In the example, the subexpression is not~\ffB\verb|x+y|\ffE{} complete (missing~\ffB\verb|z|\ffE).
The \ffB\verb|ratsubst|\ffE{} command it also modifies the resulting expression.

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai2$	subst(x+y,a,a^2+b^2); ratsubst(x+y,a,a^2+b^2);
$\maximao1$	$\color{farbaV}(y+x)^2+b^2$
$\maximao2$	$\color{farbaV}y^2+2xy+x^2+b^2$
$\maximai4$	subst(a,x+y,x+y+z); ratsubst(a,x+y,x+y+z);
$\maximao3$	$\color{farbaV}z+y+x$
$\maximao4$	$\color{farbaV}z+a$
\end{lstlisting}
%------------------------------------------------



%%---------------------------------------------------------------------------%
\section*{Limits and Derivatives}
\addcontentsline{toc}{section}{Limits and Derivatives}

In the \ffbox|Calculus| menu we find functions for solving basic problems of mathematical analysis
(limits, derivation, integration, sums of series, decomposition of a function into a Taylor polynomial,~\dots).

We calculate the limits using the command\ffB\verb|limit|\ffE.
The last parameter determines the direction of unilateral limits,
has the values~\ffB\verb|plus|\ffE{} or~\ffB\verb|minus|\ffE{} and is optional.
If not specified, Maxima calculates the limit as complex.

With the commands \ffB\verb|limit(f(x),x,a)|\ffE{} and \ffB\verb|limit(f(x),x,a,plus)|\ffE{}
we calculate the limits $\LIMITx{a}{f(x)}$ and $\LIMITx{a^+}{f(x)}$.

%------------------------------------------------
\begin{lstlisting}[lineskip=.25em]
$\maximai4$	limit(1/x,x,0);
		limit(1/x,x,0,plus); limit(1/x,x,0,minus); limit(1/x,t,0);
$\maximao1$	@\it\color{farbaV}infinity@
$\maximao2$	$\color{farbaV}\infty$
$\maximao3$	$\color{farbaV}-\infty$
$\maximao4$	$\color{farbaV}\frac1x$
\end{lstlisting}
%------------------------------------------------



If we use apostrophe~\ffB\verb|'|\ffE{} before the command, 
the command will not be executed, it will only be displayed.

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai2$	limit(((1-n)/(1+3*n))^(1+4*n),n,inf);
		'limit(((1-n)/(1+3*n))^(1+4*n),n,inf);
$\maximao1$	$\color{farbaV}0$
$\maximao2$	@\raisebox{.2em}{\scalebox{.9}{$\color{farbaV}\LIMIT{\big(\frac{1-n}{3n+1}\big)^{4n+1}}$}}@
\end{lstlisting}
%------------------------------------------------




Derivatives are calculated using the command \ffB\verb|diff|\ffE.
The parameter that determines the order of derivation is optional.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai4$	f(x):=2*x^4-3*x+sin(x);
	print("f'=",diff(f(x),x),"=",diff(f(x),x,1))$\rbDolar$
	print("f''=",diff(diff(f(x),x),x),"=",diff(f(x),x,2),
		"=",diff(f(x),x,1,x,1))$\rbDolar$
	print("f^(10)=",diff(f(x),x,10),"=",diff(f(x),x,1,x,9))$\rbDolar$
$\maximao1$	$\color{farbaV}f(x):=2x^4-3x+\sin(x)$
	$\color{farbaV}f'=\cos(x)+8x^3-3=\cos(x)+8x^3-3$
	$\color{farbaV}f''=24x^2-\sin(x)=24x^2-\sin(x)=24x^2-\sin(x)$
	$\color{farbaV}f\,\hat{}(10)=-\sin(x)=-\sin(x)$
\end{lstlisting}
%------------------------------------------------



We calculate partial derivatives using the same command.

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai3$	g(x,y):=x^3*y^2-1;
	print("g'_x=",diff(g(x,y),x),", respectively g'_y=",
		diff(g(x,y),y,1))$\rbDolar$
	print("g''_(xx)=",diff(g(x,y),x,2),", respectively g''_(yx)=",
		diff(g(x,y),y,1,x,1))$\rbDolar$
$\maximao1$	$\color{farbaV}g(x,y):=x^3y^2-1$
	@\color{farbaV}$g'\_x=3x^2y^2$, respectively $g'\_y=2x^3y$@
	@\color{farbaV}$g''\_(xx)=6xy^2$, respectively $g''\_(yx)=6x^2y$@
\end{lstlisting}
%------------------------------------------------





We calculate the Taylor polynomial $n$th degree using the command \ffB\verb|taylor|\ffE.
You can find this command in the \ffbox|Calculus| menu and the \ffbox|Get Series...| submenu.
We calculate Taylor series of functions~$f$ degree~$n$ in the middle~$c$ 
with the command \ffB\verb|taylor(f(x),x,c,n)|\ffE.
Its coefficients are obtained using the command \ffB\verb|coeff|\ffE.
The use of this command depends on the \ffB\verb|taylor|\ffE{} command.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	t1:taylor(sin(x),x,0,5); t2:taylor(sin(x),x,-1,4);
$\maximax{(t1)}$	$\color{farbaV}x-\frac{x^3}{6}+\frac{x^5}{120}+\cdots$
$\maximax{(t2)}$	$\color{farbaV}-\sin(1)+\cos(1)(x+1)+\frac{\sin(1)(x+1)^2}{2}-\frac{\cos(1)(x+1)^3}{6}-\frac{\sin(1)(x+1)^4}{24}+\cdots$
$\maximai3$	print(coeff(sin(x),x,5)," and ",coeff(t1,x,5)," ",coeff(t2,x,5))$\rbDolar$
	@\color{farbaV}$0$ and $\frac{1}{120}$  $\frac{\cos(1)}{120}$@
\end{lstlisting}
%------------------------------------------------




Taylor polynomial of polynomial is again a polynomial, only it is expressed in another form.
Practically, only the coordinate system will change in which we express the polynomial.
The beginning of the system moves from~point~$0$ to point~$-1$.

In the following example, the Taylor polynomial of a given polynomial is calculated
in another way.
Command \ffB\verb|taylor|\ffE{} gives three points at the end, even if development is closed.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	f(x):=2*x^5-x^4-3*x^3-x+1;
$\maximao1$	$\color{farbaV}f(x):=2x^5-x^4+(-3)x^3-x+1$
$\maximai2$	tp1:taylor(f(x),x,-1,5);
$\maximax{(tp1)}$	$\color{farbaV}2+4(x+1)-17(x+1)^2+21(x+1)^3-11(x+1)^4+2(x+1)^5+\cdots$
$\maximai4$	ratsimp(tp1);expand(tp1);
$\maximao3$	$\color{farbaV}2x^5-x^4-3x^3-x+1$
$\maximao4$	$\color{farbaV}2x^5-x^4-3x^3-x+1$
$\maximai6$	tpx:ratsubst(t,x+1,f(x));subst(x+1,t,tpx);
$\maximax{(tpx)}$	$\color{farbaV}2t^5-11t^4+21t^3-17t^2+4t+2$
$\maximax{(tp2)}$	$\color{farbaV}2(x+1)^5-11(x+1)^4+21(x+1)^3-17(x+1)^2+4(x+1)+2$
$\maximai7$	tp1-tp2;
$\maximao7$	$\color{farbaV}0+\cdots$
\end{lstlisting}
%------------------------------------------------
	



%%---------------------------------------------------------------------------%
\section*{Function Graphs}
\addcontentsline{toc}{section}{Function graphs}

We can plot the function graph in several ways.
The easiest way is to choose \ffbox|Plot| in the menu submenu \ffbox|Plot 2d ...|.

If we choose \ffbox|Format=\smash{gnup}lot|, the function is rendered by the command \ffB\verb|plot2d|\ffE{}
using the Open Source program \verb|Gnuplot| to a new window.
\verb|Gnuplot| is automatically installed together with Maxima.

%------------------------------------------------
\begin{lstlisting}
$\maximai1$	plot2d([sin(x),cos(x)],[x,-%pi,2*%pi],[y,-1.2,1.2],
		[plot_format, gnuplot])$\rbDolar$







	@\color{farbaV}\ffbox|\includegraphics[height=.2\textwidth]{grafy/graf01.png}|@
\end{lstlisting}
%------------------------------------------------


% ...........................................................................................
%
% tu mozno zvacsit alebo zmensit obrazok v prikaze.... \includegraphics[height=.25\textwidth]
% ale potom je potrebne vynechat viac riadkov pred prikazom 
%
% ...........................................................................................

The graphs of the sine and cosine functions were not displayed in the real ratio of the $x$ and $y$ axes, but were optimized for the screen.
We have to use e.g. \ffB\verb|same_xy|\ffE{} parameter for proper display.

%------------------------------------------------
\begin{lstlisting}
$\maximai1$	plot2d([sin(x),cos(x)],[x,-%pi,2*%pi],[y,-1.2,1.2],
		[plot_format, gnuplot],[same_xy])$\rbDolar$







	@\color{farbaV}\ffbox|\includegraphics[height=.2\textwidth]{grafy/graf01b.png}|@
\end{lstlisting}
%------------------------------------------------






If we choose \ffbox|Format=wxmaxima|, 
Maxima will plot the graph using the command \ffB\verb|plot2d|\ffE{} to a new window.
We can only save the image in postscript.

%------------------------------------------------
\begin{lstlisting}
$\maximai1$	plot2d([sin(x),cos(x)],[x,-%pi,2*%pi],[y,-1.2,1.2],
		[plot_format, xmaxima])$\rbDolar$








	@\color{farbaV}\ffbox|\includegraphics[height=.25\textwidth]{grafy/graf02.jpg}|@
\end{lstlisting}
%------------------------------------------------




If we choose \ffbox|Format=inline|, Maxima draws a graph using the command \ffB\verb|wxplot2d|\ffE{}
into your environment.

%------------------------------------------------
\begin{lstlisting}
$\maximai1$	wxplot2d([sin(x),cos(x)],[x,-%pi,2*%pi],[y,-1.2,1.2])$\rbDolar$








$\maximao1$	@\color{farbaV}\smash{\includegraphics[height=.25\textwidth]{grafy/graf03.png}}@
\end{lstlisting}
%------------------------------------------------




Commands~\ffB\verb|plot2d|\ffE{} and \ffB\verb|wxplot2d|\ffE{} they have the same syntax and have many more parameters.
Parameters can be found, for example, with the command \ffB\verb|describe(plot2d)|\ffE.


%------------------------------------------------
\begin{lstlisting}
$\maximai1$	wxdraw2d(xaxis=true,yaxis=true,xrange=[0,2*%pi],yrange=[-1.2,1.2],
	color=blue,explicit((sin(x)),x,0,2*%pi),
	color=red,explicit((cos(x)),x,0,2*%pi))$\rbDolar$








$\maximao1$	@\color{farbaV}\smash{\includegraphics[height=.25\textwidth]{grafy/graf11.png}}@
\end{lstlisting}
%------------------------------------------------

\bigskip

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	draw2d(xaxis=true,yaxis=true,xrange=[0,2*%pi],yrange=[-1.2,1.2],
	color=blue,explicit((sin(x)),x,0,2*%pi),
	color=red,explicit((cos(x)),x,0,2*%pi))$\rbDolar$






	@\color{farbaV}\ffbox|\includegraphics[height=.25\textwidth]{grafy/graf12.png}|@
\end{lstlisting}
%------------------------------------------------


It is better to use the \ffB\verb|wxdraw2d|\ffE{} command to print function graphs
or \ffB\verb|draw2d|\ffE, which should be routed to the output of \verb|Gnuplot|.
These commands have a slightly different syntax than the \ffB\verb|wxplot2d|\ffE, \ffB\verb|plot2d|\ffE.
The print parameters are simpler and clearer.
The plotted function must be located in the command \ffB\verb|explicit|\ffE,
\ffB\verb|parametric|\ffE{} or \ffB\verb|implicit|\ffE.




We plot a parametric curve or function in a similar way.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	draw2d(xaxis=true,yaxis=true,xrange=[-%pi,%pi],yrange=[-1.2,1.2],
	color=blue,explicit((sin(x)),x,-%pi,%pi),
	color=red,nticks=300,parametric(cos(t),sin(t),t,0,2*%pi))$\rbDolar$

	




	@\color{farbaV}\ffbox|\includegraphics[height=.25\textwidth]{grafy/graf16.png}|@
\end{lstlisting}
%------------------------------------------------





%%---------------------------------------------------------------------------%
\section*{Sequences and Series}
\addcontentsline{toc}{section}{Sequences and Series}

Sequences can be created in Maxima, for example, using the command \ffB\verb|makelist|\ffE{}
or with the statements of the cycle \ffB\verb|for..do|\ffE.


Command \ffB\verb|makelist|\ffE{} creates a list that we can display as a whole and by members.

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai2$	S1:makelist(2*n^2-1,n,1,10);S2:makelist(2*n^2-1,n,2,10,2);
$\maximax{(S1)}$	$\color{farbaV}[1,7,17,31,49,71,97,127,161,199]$
$\maximax{(S2)}$	$\color{farbaV}[7,31,71,127,199]$
$\maximai4$	S1[1];S1[10];
$\maximao3$	$\color{farbaV}1$
$\maximao4$	$\color{farbaV}199$
\end{lstlisting}
%------------------------------------------------




Arranged pairs are enclosed in square brackets and can be displayed as points in a plane.
In the following example, a sequence is also generated with its patterns and then plotted with a command
\ffB\verb|draw2d|\ffE.

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	S1:makelist([n,(2*n-1)/(n+1)],n,1,10);
$\maximax{(S1)}$	$\color{farbaV}[[1,\smash{\frac12}],[2,1],[3,\smash{\frac54}],[4,\smash{\frac75}],[5,\smash{\frac32}],[6,\smash{\frac{11}{7}}],[7,\smash{\frac{13}{8}}],[8,\smash{\frac53}],[9,\smash{\frac{17}{10}}],[10,\smash{\frac{19}{11}}]]$
$\maximai2$	draw2d(grid=true,xaxis=true,yaxis=true,xrange=[0,11],
	yrange=[-0.5,2.5],color=blue,explicit((2*n-1)/(n+1),n,0.5,10.5),
	point_type=7,color=red,points(S1))$\rbDolar$






	@\color{farbaV}\ffbox|\includegraphics[height=.25\textwidth]{grafy/graf21.png}|@
\end{lstlisting}
%------------------------------------------------




Using the command \ffB\verb|for..do|\ffE{} we will list several members of the sequence $\POSTUPNOST{2n^2-1}$.

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	(for n:1 thru 12 do (a_n: 2*n^2-1, print(a_n)) )$\rbDolar$
	$\color{farbaV}1$
	$\color{farbaV}7$
	$\color{farbaV}17$
	$\color{farbaV}31$
	$\color{farbaV}49$
	$\color{farbaV}71$
	$\color{farbaV}97$
	$\color{farbaV}127$
	$\color{farbaV}161$
	$\color{farbaV}199$
	$\color{farbaV}241$
	$\color{farbaV}287$
\end{lstlisting}
%------------------------------------------------

A nice example of using the command \ffB\verb|for..do|\ffE{} is a Fibonacci sequence.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai3$	a0:0$\rbDolar$ a1:1$\rbDolar$ 
		(for i:1 thru 12 do (an:a1+a0, print(an), a1:a0, a0:an))$\rbDolar$
	$\color{farbaV}1$
	$\color{farbaV}1$
	$\color{farbaV}2$
	$\color{farbaV}3$
	$\color{farbaV}5$
	$\color{farbaV}8$
	$\color{farbaV}13$
	$\color{farbaV}21$
	$\color{farbaV}34$
	$\color{farbaV}55$
	$\color{farbaV}89$
	$\color{farbaV}144$
\end{lstlisting}
%------------------------------------------------



We calculate the finite and infinite sum using the command \ffB\verb|sum|\ffE.


%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	sum(2*n^2-1,n,1,8);
$\maximao1$	$\color{farbaV}400$
\end{lstlisting}




With this command, Maxima can calculate the exact sum of some infinite series.
The sum of the series can be entered in the menu \ffbox|Calculus| and the \ffbox|Calculate Sum...| submenu.


%------------------------------------------------
\begin{lstlisting}[lineskip=1em]
$\maximai2$	sum(1/k^2,k,1,inf); 
	sum(1/k^2,k,1,inf),simpsum; 
$\maximao1$	@\color{farbaV}\raisebox{.35em}{\scalebox{.85}{$\RADk{\big(\frac{1}{k^2}\big)}$}}@
$\maximao2$	$\color{farbaV}\frac{\pi^2}{6}$
\end{lstlisting}
%------------------------------------------------




The number series from the previous example can be graphically represented as follows.

%------------------------------------------------
\begin{lstlisting}[lineskip=.5em]
$\maximai1$	a(n):=1/n^2$\rbDolar$ rec:makelist(rectangle([i-1,0],[i,a(i)]),i,1,10)$\rbDolar$
	draw2d(grid=true,xaxis=true,yaxis=true,xrange=[-1,11],
	yrange=[-0.2,1.2],border=true,color=black,fill_color=red,rec,
	color=blue,explicit(a(n),n,0,11))$\rbDolar$






	@\color{farbaV}\ffbox|\includegraphics[height=.25\textwidth]{graf17.png}|@
\end{lstlisting}
%------------------------------------------------


\bigskip


