# Maple/Getting Started
## Chapter 1: Getting Started with Maple
### Before You Begin

All the commands given to Maple are in the areas marked with >. These are the input areas. Press enter to execute the command.
The lines of code must end with either a semicolon or a colon. Note the difference between them:
$p-\ln \left(p\right)$
If the line of code ends with a semicolon, the order is validated and the software displays the answer in the output area. If the line of code ends with a colon, the order is validated, but the answer is not displayed.

### Simple computations with Maple

${\frac {50}{21}}$
$5\,$
$1307674368000\,$
$1307674368000\,$
$9\,$
$7.537240874\,$
$56.81\,$

### Using variables with Maple

Like any other programming language, Maple allows us to assign values to named variables. This often makes programs more readable and it allows us to save results for use later in the calculation. Here, 2.14 is assigned to the variable p. We can then compute $p-\ln \left(p\right)$ so that p is evaluated (replaced by) 2.14:
$p:=2.14\,$
$1.379194171\,$
You can also use more than one variable in a single expression:
$x:=2\,a-2.14$
$2\,a-2.14-1.462873884\,{\sqrt {a}}$
$expr:={a{x}}^{2}+bx+c=0\,$

### Commands to manipulate expressions in Maple

Maple has a wide range of commands to help you manipulate expressions:
$f:=\left(a+b\right)^{6}$
${a}^{6}+6\,{a}^{5}b+15\,{a}^{4}{b}^{2}+20\,{a}^{3}{b}^{3}+15\,{a}^{2}{b}^{4}+6\,a{b}^{5}+{b}^{6}$
$\left(a+b\right)^{6}$
${a}^{6}+6\,{a}^{5}b+15\,{a}^{4}{b}^{2}+20\,{a}^{3}{b}^{3}+15\,{a}^{2}{b}^{4}+6\,a{b}^{5}+{b}^{6}$
$\left(\sin(x)\right)^{2}+\left(\cos(x)\right)^{2}$
$1\,$
Here, the % symbol recalls the last computation made by Maple. %% means you recalls the computation made two steps back. %%% will recall the answer to the computation make three steps back. If you wish to recall answers father back, you will have to have assigned them to a variable.
You can also substitute values for the variables in an expression with the commands subs and two-argument eval:
$7\,$
$7\,$
The command subs makes syntactic substitution,
$\sin(0)\,$
while eval performs substitution followed by evaluation
$0\,$
$\left(c+b\right)^{6}$
${\frac {7529536}{15625}}$
The command subs substitutes bound (dummy) variables while eval does not:
$\int _{0}^{1}\!f\left(u\right){du}$
$\int _{0}^{1}\!f\left(x\right){dx}$
The command eval does simultaneous substitution while the command subs does sequential substitution:
$[x,x]\,$
$[y,x]\,$
The following are equivalent:
Simultaneous substitution
$[y,x]\,$
$[y,x]\,$
and
Sequential substitution
$[x,x]\,$
$[x,x]\,$
The command evalf calculates a floating point (numeric) approximation of an expression. You may also specify the desired precision.
$1.732050808\,$
$1.7320508075688772935274463415058723669428052538104\,$
$1.7320508075688772935274463415058723669428052538104\,$
print, lprint and printf are commands used to display a mathematical expression. print displays the expression using the current pretty-printing method. lprint displays the expression in 1D format (no pretty-printing), as one would type as input to Maple. printf is the same function used in C or C++ language, where you can display variables using formats: %d represents an integer variable, %f a floating number and \n breaks a line of text:
$f:=a-{\frac {3}{a}}+{\frac {1}{{a}^{2}+1}}$
$a-{\frac {3}{a}}+{\frac {1}{{a}^{2}+1}}$
a-3/a+1/(a^2+1)
123 2.176367

### Defining a function with Maple

The simplest form to define a function uses the arrow (map) operator ->
$f:=t\rightarrow \sin(t)-t$
$\sin(3\,x+2)-3\,x-2$
Note:
defines f as a function, i.e.
$2u+2\,$
defines f as a procedure with a "remember table" that is assigned only for the argument x:
$\mathrm {f} (u)\,$
and
is an equation.

### Calculus with Maple

Derivatives of expressions can be taken with the diff command:
Multiple partial derivatives can be given as a list. To take the derivative of g with respect to u then v:
Maple can also take the derivative of functions using the D operator
If a function has more than one variable, the variable can be specified as an index:
Notice the difference between diff and D: diff operates on an expression, and returns an expression while D operates on a function and returns another function.
Maple can be used to find a primitive, indefinite integral or anti-derivative of an expression. For example, to get indefinite integrals of the function f(t) according to t and the function g(u,v,w) according to v, the following commands can be entered:
$\int \left(\sin(t)-t\right)\,dt=-\cos(t)-{\frac {1}{2}}\,{t}^{2}$
$\int \left({\frac {1}{u}}+e^{u+v}+(u-v+w)^{2}\right)\,{dv}={\frac {v}{u}}+{e^{u+v}}-{\frac {1}{3}}(u-v+w)^{3}$
Note the difference between the commands Int and int. The former is the inert form, it just displays the integral. The latter is the active form and computes its value.
Maple can also compute definite integrals:
$\int _{0}^{\pi }\left(\sin(t)-t\right)\,dt=2-{\frac {1}{2}}\pi ^{2}$
To evalue an inert integral, one can use the command value:
$-\cos(t)-{\frac {1}{2}}\,{t}^{2}$
The other use of this inert form is the numerical approximation of definite integrals:
$1.57079633$
This should give the same answer as evalf(int(f(t), t=0..Pi)) but it is computed differently. When the inert form of the integral is used Maple computes an approximation of the area under the curve using the definition of definite integration. When then int form is used, and exact value for the definite integral is computed, and then that value is numerically approximated. Using the inert form to compute the approximation directly can be much faster for large problems.

### Limits, sums and products with Maple

You can also find numeric and symbolic values of sums, limits and products using respectively the functions sum, limit and product:
${\frac {2}{3}}$
$-\infty$
$\sum _{i=1}^{10}i^{2}=385$
$\prod _{i=1}^{10}{\frac {1}{i}}={\frac {1}{3628800}}$
The commands Sum and Product are inert, they do not actually compute the sum or the product.

### Solving equations with Maple

The solve(eqn,x) function tries to find the value of x in eqn. You can also use more variables or more equations using solve({eqn1,eqn2,...},{x,y,...}):
$-1+2{\sqrt {2}}$
${\frac {14}{25}}t-{12}{25}$
$\left\{a={\frac {13}{4}},b={\frac {5}{4}}\right\}$
Sometimes, the exact solution of an equation might not be found. You can then use the fsolve to get a numerical approximation:
$0.7390851332$
$\{t=0.6941457205,u=0.6655340191\}$

### Giving names to solutions

The solution can be stored in a variable, as any other expression
$solution:=\left\{b=-{\frac {1}{2}}{\frac {x^{2}-1}{x}},~a={\frac {1}{2}}{\frac {x^{2}+1}{x}}\right\}$
In the example, variable solution is assigned value, than can be used in following calculations. Sometimes, it worth to keep parts of the solution in independent variables. It can be done with appropriate substitution. For the ability to reproduce each step of calculus, it is better not to replace variables (a,b) used to write the original equaitons, but create the new names, for example, solutiona" and "solutionb":
$solutiona:={\frac {1}{2}}{\frac {x^{2}+1}{x}}$
$solutionb:=-{\frac {1}{2}}{\frac {x^{2}-1}{x}}$
Then, these expressions can be accessed through their identifiers in some plots or future calculation.

### Plotting functions with Maple

To plot a function f(x), use the command plot(f(x),x):