**<< Previous page TOC INDEX Next page >>**

## Numerical Tools in Mathematica

In Mathematica, we can find the roots of simple polynomials in closed form, while larger polynomials can be factored numerically in eitherMatlab or Mathematica. Look to Mathematica to provide the most sophisticated symbolic mathematical manipulation, and look for Matlab to provide the best numerical algorithms, as a general rule.

One way to implicitly find the roots of a polynomial is to

factorit in Mathematica:In[1]: p[xFactor[] works only with exact Integers or Rational coefficients, not with Real numbers.] := x^2 + 5 x + 6 In[2]: Factor[p[x]] Out[2]: (2 + x)*(3 + x)Alternatively, we can explicitly solve for the roots of low-order polynomials in Mathematica:

In[1]: p[x] := a x^2 + b x + c In[2]: Solve[p[x]==0,x] Out[2]: {{x -> (-(b/a) + (b^2/a^2 - (4*c)/a)^(^{1}⁄_{2}))/2}, {x -> (-(b/a) - (b^2/a^2 - (4*c)/a)^(^{1}⁄_{2}))/2}}Closed-form solutions work for polynomials of order one through four. Higher orders, in general, must be dealt with numerically, as shown below:

In[1]: p[x_] := x^5 + 5 x + 7 In[2]: Solve[p[x]==0,x] Out[2]: {ToRules[Roots[5*x + x^5 == -7, x]]} In[3]: N[Solve[p[x]==0,x]] Out[3]: {{x -> -1.090942496109028}, {x -> -0.7550479250175501 - 1.275010619237742*I}, {x -> -0.7550479250175501 + 1.275010619237742*I}, {x -> 1.300519173072064 - 1.109447238195959*I}, {x -> 1.300519173072064 + 1.109447238195959I}}Mathematica has the following primitives for dealing with complex numbers(The “?” operator returns a short description of the symbol to its right):

In[1]: ?I Out[1]: I represents the imaginary unit Sqrt[-1]. In[2]: ?Re Out[2]: Re[z] gives the real part of the complex number z. In[3]: ?Im Out[3]: Im[z] gives the imaginary part of the complex number z. In[4]: ?Conj Out[4]: Conjugate[z] gives the complex conjugate of the complex number z. In[5]: ?Abs Out[5]: Abs[z] gives the absolute value of the real or complex number z. In[6]: ?Arg Out[6]: Arg[z] gives the argument of z.