1.1 NUMERIC CALCULUS with MATHEMATICA
We canuse Mathematica as a powerful numerical computer. Most calculators handlenumbers only with a degree of precision preset, however Mathematica makes exactcalculations with precision which is necessary. In addition, unlikecalculators, we can perform operations not only with individual numbers, butalso with objects such as arrays. Most ofthe themes of the classical numerical calculus, are treated in this software.It supports matrix calculus, statistics, interpolation, fit by least squares,numerical integration, minimization of functions, linear programming, numericalalgebraic and differential equations resolution and a long list of processes ofnumerical analysis that we'll see as the successive issues of this book. Here aresome examples of numerical calculus with Mathematica.
In[1]: = 4 + 3Out[1] = 7 (2) Alsowe can get the exact value of 3 high at 100, without having previously setprecision, just for this purpose press 3 ^ 100.
In[2]: = 3 ^ 100Out[2] = 515377520732011331036461129765621272702107522001 (3) Alsowe can use the N function to pass the result of the operation immediately priorto scientific notation.
In[2]: = 3 ^ 100Out[2] = 515377520732011331036461129765621272702107522001 (3) Alsowe can use the N function to pass the result of the operation immediately priorto scientific notation.
To do this, type N [%] (symbol % we use to refer to theimmediately preceding calculation). In[3]: = N [%]Out[3] = 5.153775207320114 10 (4) Alsowe can perform operations with a fixed degree of precision. If we find thesquare root of 5 with 25 digits, simply enter the expression N [Sqrt [5], 25]. In[4]: = N [Sqrt [5], 25]Out[4] = 2.2360679774997896964091737 (5) Alsowe can work with complex numbers. We will get the result of the operation (2 +3i) raised to 10, by typing the expression (2 + 3I) ^ 10. In[5]: = (2 + 3 * I) ^ 10Out[5] = 341525 145668 I (6) Alsowe can calculate the value of the Bessel function in section 13.5.
This typeBesselJ [0,13.5]. In[6]: = BesselJ [0, 13.5]Out[6] = 0.2149891658804008 (7) Alsocan calculate the value of Rieman function Z at the point (1/2 + 13i) with 15digits. Just press N [Zeta [1/2 + 13I], 15]. IIn[7] := N[Zeta[1/2 + 13*I], 15]Out[7] = 0.4430047825053677 0.6554830983211705 (8) Alsowe can perform numeric integrals. To calculate the integral between 0 and p of (SIN(x)) sine function typeexpression NIntegrate [Sin [no [x]], {x, 0, Pi}]. In [8]: =NIntegrate [Sin [no [x]], {x, 0, Pi}]Out[8] = 1.78648748195006 .
Thesethemes will be treated more thoroughly in successive chapters throughout thebook.
1.2 SYMBOLIC CalculUS with MATHEMATICA
Mathematicaperfectly handled the symbolic mathematical computation, manipulating formulaeand algebraic expressions easily and quickly and can perform the majority ofalgebraic operations. You can expand, factor and simplify polynomials andrational and trigonometric expressions, you can find algebraic solutions ofpolynomial equations and systems of equations, can evaluate derivatives andintegrals symbolically and find functions solution of differential equations,you can manipulate powers, limits and many other facets of algebraic mathematicsseries. Here aresome examples of symbolic computation with Mathematica. 1) Wecan raise the bucket the following algebraic expression: (x + 1) (x+2) (x+2) ^2. This is done by typing the following expression: Expand [((x + 1) (x+2)(x+2) ^ 2) ^ 3].
The result will be another algebraic expression: In[1]: = Expand [((x + 1) *(x + 2) (x + 2) ^ 2) ^ 3]2 3Out[1] = 8- 12 x- 6 x- x 2) Wecan factor the result of the calculation on the previous example by typing Factor[%] In[2]: = Factor [%]Out[2] = (2 + x) 3) Wecan resolve the indefinite integral of the function (x ^ 2) Sin(x) ^ 2 bytyping Integrate [x ^ 2 Sin [x] ^ 2 x] In[3]:= Integrate[x^2*Sin[x]^2, x]Out[3]=3 2x x Cos[2 x] (1- 2 x) Sin [2 x]--- -------------+ -----------------------6 4 8 4) Wecan find the derivative of the result of the integral above by typing D [% x] In[4]:= D[%, x] Out[4]= 2 2x Cos[2 x] (1 - 2 x ) Cos[2 x]--- -------------+-----------------------2 4 4 5)We can simplify the result of the derivative before typing Simplify [%] In[5]:= Simplify[%]2 2Out[5]= x Sin[x] 6) Wecan develop in power of order 14 series the result from the previous example bytyping Series [% {x, 0.14}] In[6]:= Series[%, {x, 0, 14}]Out[6]=6 8 10 12 144 x 2 x x 2 x 2 x 15x - -- + ---- - -----+-------- - ----------+ O[x]3 45 315 14175 467775 7) We can solve theequation 3ax - 7 x ^ 2 + x ^ 3 = 0 (a, is a parameter) by typing Solve [3ax 7 x^ 2 + x ^ 3 = 0] In[7]:= Solve[3*ax - 7*x^2 + x^3 == 0, x]Out[7]=1/37 49 2{{x->-- + ------------------------------------------------------------------+3 2 1/33 (686 - 81 ax + 9 Sqrt[-1372 ax + 81 ax ] )2 1/3(686 - 81 ax + 9 Sqrt[-1372 ax + 81 ax ] )+ ---------------------------------------------------------------},1/33 21/37 I -49 2{x-> - + - Sqrt[3] (----------------------------------------------------------+3 2 2 1/33(686-81ax+9Sqrt[-1372ax+81ax ] )2 1/3(686 - 81 ax + 9 Sqrt[-1372 ax + 81 ax ] )+ -----------------------------------------------------------------)-1/33 21/349 2- (---------------------------------------------------------------------+2 1/33 (686 - 81 ax + 9 Sqrt[-1372 ax + 81 ax ] )2 1/3(686 - 81 ax + 9 Sqrt[-1372 ax + 81 ax ] )+ ------------------------------------------------------------------)/ 2},1/33 21/37 I -49 2{x-> - - - Sqrt[3] (--------------------------------------------------------+3 2 2 1/33 (686-81ax+9 Sqrt[-1372ax+81ax ] )2 1/3(686 - 81 ax + 9 Sqrt[-1372 ax + 81 ax ] )+ ------------------------------------------------------------------)-1/33 21/349 2- (-----------------------------------------------------------------------+2 1/33 (686 - 81 ax + 9 Sqrt[-1372 ax + 81 ax ] )2 1/3(686 81 ax + Sqrt 9 [1372 ax + 81 ax])+ -----------------------------------------------------------------)/ 2}}1/33 2 8) We can find fivecomplex solutions of the equation x ^ 5 + 2 x + 1 = 0 by typing NSolve [x ^ 5 +2 x + 1 = 0, x] In[8]:= NSolve[x^5 + 2*x + 1 == 0, x]Out[8]= {{x -> -0.7018735688558619 - 0.879697197929824 I},{x -> -0.7018735688558619 + 0.879697197929824 I},{x -> -0.486389035934543},{x -> 0.945068086823133 - 0.854517514439046 I},{{x > 0.945068086823133 + 0.854517514439046 I}} 9) Wecan generate a matrix 3 x 3 whose (i, j) element is 1 / (i+j+1) by typing m =Table [1 / (i + j + 1), {i, 3}, {j, 3}] In[9]:= m = Table[1/(i + j + 1), {i, 3}, {j, 3}]Out[9] = {{1/3, 1/4, 1/5}, {1/4, 1/5, 1/6}, {1/5, 1/6, 1/7}} 10) Wecan invert the matrix above, typing Inverse [m] In[10]: = Inverse [m]Out[10] = {{300, 900, 630}, {900, 2880, 2100}, {630, 2100, 1575}} 11) Wecan find the determinant of the matrix m xIdentidad (3.3) tecleando Det[ m -x IdentityMatrix[3] ] In[11]:= Det[m - x*IdentityMatrix[3]]2 3Out[11] = (1 4755 x + 255600 x - 378000 x ) / 378000 12) Wecan find all the permutations of the three elements {e, f, g} tecleandoPermutations[{e, f, g}]