# Mathematica/SimpleCalculations
### Simple computations with Mathematica

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

### Using variables with Mathematica

Like any other programming language, Mathematica 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) as 2.14:
$2.14\,$
$1.379194171\,$
You can also use more than one variable in a single expression:
$2\,a-2.14$
$2\,a-2.14-1.462873884\,{\sqrt {a}}$
${a{x}}^{2}+bx+c==0\,$

### Commands to manipulate expressions in Mathematica

Mathematica 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 Mathematica. %% 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 command ReplaceAll usually entered /.
$7\,$
The command N calculates a floating point (numeric) approximation of an expression. You may also specify the desired precision.
$1.732050808\,$
$1.7320508075688772935274463415058723669428052538104\,$

### Defining a function with Mathematica

You define a function using patterns (_) and SetDelayed ( :=)
$-2x+\sin(2x+2)-2$

### Calculus with Mathematica

Derivatives of expressions can be taken with the D command:
Multiple partial derivatives can be given as a list. To take the derivative of g with respect to u then v:
Mathematica can be used to find a primitive, indefinite integral or anti-derivative of an expression.
${\frac {\tan ^{-1}\left({\frac {2x-1}{\sqrt {3}}}\right)}{\sqrt {3}}}+{\frac {1}{3}}\log(x+1)-{\frac {1}{6}}\log \left(x^{2}-x+1\right)$
Mathematica can also compute definite integrals:
$2-{\frac {1}{2}}\pi ^{2}$
NIntegrate is used for numerical integration:
$1.57079633\,$

### Limits, sums and products with Mathematica

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$
$385\,$
$={\frac {1}{3628800}}$

### Solving equations with Mathematica

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,...}]
$\left\{\left\{t\to -1+2{\sqrt {2}}\right\}\right\}$
$\left\{\left\{u\to {\frac {2}{25}}(7t-6)\right\}\right\}$
$\left\{\left\{a\to {\frac {13}{4}},b\to {\frac {5}{4}}\right\}\right\}$
The following Mathematica sequence will find the determinant of the 6×6 matrix whose i, j'th entry contains ij.
So the determinant of such a matrix is 0 (i.e. it is singular).
The following numerically calculates the root of the equation e$^x$ = x$^2$ + 2, starting at the point x = -1.
Mathematica can do integral and differential calculus, in particular evaluation of integrals in terms of special functions. For example:
Here, E and I are the fundamental constants e and i respectively, and PolyLog[s,z] is the polylogarithm function $\mathrm {Li} _{s}\left(z\right)$.
Symbolic sums can be calculated. For example: