Mathematica

``SuperCalculator''

In the Mathematica examples below, boldface type is Input, regular type is Output.

Mathematica tries to do exact arithmetic on integers and symbols; floating point numbers (e.g. numbers with a decimal point) are treated differently in many cases.

Function N converts to floating point.


{ Sqrt[2],  Sqrt[2.0],  Sqrt[9Pi], N[Sqrt[9Pi],20] }

{2^(1/2), 1.414213562373095, 3*Pi^(1/2), 5.3173615527165480819}

Algebraic expressions can be manipulated with commands like Expand, Factor, Simplify, Solve;


Expand[ (x+y)^3 ]
Factor[ a^3 - 1 ]
Simplify[ (x+y)^2-(x-y)^2 ]

x^3 + 3*x^2*y + 3*x*y^2 + y^3
(-1 + a)*(1 + a + a^2)
4*x*y

Complex arithmetic? Of course!


{ (2-3I)(4+I),     Sqrt[-1.2+0.3I],     E^(I Pi) }

{11 - 10*I, 0.1358890865472614 + 1.103841403392104*I, -1}

Solves equations; exactly when possible, numerically if necessary


Solve[x^2 - x == 1, x]

{{x -> (1 - 5^(1/2))/2}, {x -> (1 + 5^(1/2))/2}}

A floating-point coefficient (anything with a decimal point) tells Mma to solve numerically:


Solve[ x^2 - x == 1.0, x]

{{x -> -0.6180339887498949}, {x -> 1.618033988749895}}

Fifth-degree polynomials are not, in general, solvable in terms of roots:


soln = Solve[ x^5 + x^3 - x == 20, x ]

{ToRules[Roots[-x + x^3 + x^5 == 20, x]]}

...but numerical solutions, to any given precision, are always available:


soln // N

      {{x -> -1.372125450681085 - 1.095936744606096 I}, 
       {x -> -1.372125450681085 + 1.095936744606096 I}, 
       {x -> 0.4973294258052813 - 1.859979470929126 I}, 
       {x -> 0.4973294258052813 + 1.859979470929126 I}, 
       {x -> 1.749592049751608}}

x /. N[soln]

    {-1.372125450681085 - 1.095936744606096 I, 
     -1.372125450681085 + 1.095936744606096 I, 
      0.4973294258052813 - 1.859979470929126 I, 
      0.4973294258052813 + 1.859979470929126 I,   1.749592049751608}

Simultaneous equations are grouped in curly brackets {}:


Solve[ { x+y==3,  2x-3y==7 }, {x,y} ]

{{x -> 16/5, y -> -1/5}}

For solving nonlinear equations numerically one can use FindRoot


nlroots = FindRoot[{2 a b == Sin[b]+3,  b==7^a },
		{a, 0, 1}, {b, 1, 9}, WorkingPrecision -> 40]

    {a -> 0.5508994143246705000988269421867181741894, 
     b -> 2.9212183179654732633290233970612014287913}


Next: Plotting Functions
Table of Contents