1.1 Calculation NUMERIC with MATHEMATICA
We can use Mathematica as apowerful numerical computer. Most calculators handle numbers only with a degreeof precision preset, however Mathematica makes exact calculations withprecision which is necessary. In addition, unlike calculators, we can performoperations not only with individual numbers, but also with objects such asarrays. Most of the themes of theclassical numerical calculus, are treated in this software. It supports matrixcalculus, statistics, interpolation, fit by least squares, numerical integration,minimization of functions, linear programming, numerical algebraic anddifferential equations resolution and a long list of processes of numericalanalysis that we'll see as the successive issues of this book.
Here are some examples ofnumerical calculus with Mathematica. (As we all know, to get the resultsnecessary type mayusculas+enter once written corresponding expressions) (1) We can simply calculate4 + 3 and get as a result 7, to do this, just type 4 + 3 (and then shift +Enter). In[1]: = 4 + 3Out[1] = 7 (2) Also we can get theexact value of 3 high at 100, without having previously set precision, just forthis purpose press 3 ^ 100. In[2]: = 3 ^ 100Out[2] = 515377520732011331036461129765621272702107522001 (3) Also we can use the Nfunction to pass the result of the operation immediately prior to scientificnotation. To do this, type N [%] (symbol % we use to refer to the immediatelypreceding calculation). In[3]: = N [%]Out[3] = 5.153775207320114 10 (4) Also we can performoperations with a fixed degree of precision.
If we find the square root of 5with 25 digits, simply enter the expression N [Sqrt [5], 25]. In[4]: = N [Sqrt [5], 25]Out[4] = 2.2360679774997896964091737 (5) Also we can work withcomplex 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) Also we can calculatethe value of the Bessel function in section 13.5. This type BesselJ [0,13.5]. In[6]: = BesselJ [0, 13.5]Out[6] = 0.2149891658804008 (7) Also can calculate thevalue of Rieman function Z at the point (1/2 + 13i) with 15 digits.
Just pressN [Zeta [1/2 + 13I], 15]. IIn[7] := N[Zeta[1/2 + 13*I], 15]Out[7] = 0.4430047825053677 0.6554830983211705 (8) Also we can performnumeric integrals. To calculate the integral between 0 and p of (SIN(x)) sine function type expressionNIntegrate [Sin [no [x]], {x, 0, Pi}]. In [8]: =NIntegrate [Sin [no [x]], {x, 0, Pi}]Out[8] = 1.78648748195006 . These themes will betreated more thoroughly in successive chapters throughout the book.
1.2 SYMBOLIC Calculation with MATHEMATICA
Mathematica perfectlyhandled the symbolic mathematical computation, manipulating formulae andalgebraic 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 algebraicmathematics series. Here are some examples ofsymbolic computation with Mathematica. 1) We can raise the bucketthe following algebraic expression: (x + 1) (x+2) (x+2) ^ 2. This is done bytyping the following expression: Expand [((x + 1) (x+2) (x+2) ^ 2) ^ 3]. Theresult 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) We can factor the resultof the calculation on the previous example by typing Factor [%] In[2]: = Factor [%]Out[2] = (2 + x) 3) We can resolve theindefinite integral of the function (x ^ 2) Sin(x) ^ 2 by typing 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) We can find thederivative 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 theresult of the derivative before typing Simplify [%] In[5]:= Simplify[%]2 2Out[5]= x Sin[x] 6) We can develop in powerof order 14 series the result from the previous example by typing 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 the equation 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 five complex solutionsof 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) We can generate a matrix3 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) We can invert the matrixabove, typing Inverse [m] In[10]: = Inverse [m]Out[10] = {{300, 900, 630}, {900, 2880, 2100}, {630, 2100, 1575}} 11) We can find thedeterminant of the matrix m xIdentidad (3.3) tecleando Det[ m - xIdentityMatrix[3] ] In[11]:= Det[m - x*IdentityMatrix[3]]2 3Out[11] = (1 4755 x + 255600 x - 378000 x ) / 378000