Common Mathematical Tasks

Solving equations

Exact solutions:

Solve[{(x^2) + 4  (y^2) == 32, 7 - (y^2) == x}, {x, y}]

Numerical solutions: (2 methods)

NSolve - Useful for mainly systems of polynomials; no initial guess required, finds multiple solutions (2 equivalent forms)

NSolve[{(x^2) + 4  (y^2) == 32, 7 - (y^2) == x}, {x, y}]

Solve[{(x^2) + 4  (y^2) == 32, 7 - (y^2) == x}, {x, y}] // 
      N

FindRoot - Useful for equations involving transcendental functions; must supply initial guess (uses Newton's method)

FindRoot[Sin[x] == (x^2), {x, 2}]

Transcendental - Notice the warnings

NSolve[Sin[2  x] + Cos[3  x] == 0.5, x]

NSolve[Sin[2  x] == 3/4, x]

Solve[Sin[x] == (x^2), x]

This solution CAN be approximated,  however:

FindRoot[Sin[x] == (x^2), {x, 2}]

(note that you do have to supply an initial guess,  
      however)

Graphs to examine solutions:

<< Graphics`

ImplicitPlot[{(x^2) + 4  (y^2) == 32, 7 - (y^2) == x}, {x, -8, 
        8}]

Symbolic solutions:

Solve[y == ((a x)/(1 - b (x^2))), x]

Solve[a (x^3) + b (x^2) + c x + d == 0, x]

Evaluating expressions and functions

Evaluating expressions:

Method 1:  Define the values beforehand:

x = 5  a

Sin[3  (x^2)]/(Sqrt[2  (x^4)])

Use Simplify with any appropriate restricitons on the domains involved to reduce this.

Simplify[Sin[75 (a^2)]/(25 (Sqrt[2]) (Sqrt[(a^4)])), a > 0]

WARNING:  Use Clear to "unassign" this value from x or you can get into real trouble

∫(x^2) \[DifferentialD]x

The error ocurred because, as far as Mathematica is concerned, x=5a still.

Clear[x]

∫(x^2) \[DifferentialD]x

NOW it works properly.

Method 2:  Use the "ReplaceAll" operator /.

Sin[3  (x^2)]/(Sqrt[2  (x^4)]) /. x -> 5  a

Notice that this does not require the use of the Clear command:

x

In general, although this is a little less intuitive to use than the previous method of defining the values beforehand, it has less chance of unintended consequences (due to forgetting to clear a variable).

Requiring an approximate numeric result (general case)

Sin[(π/12)]

Sin[(π/12)] // N

This can also be accomplished by adding a decimal point to any number entered:

Sin[(π/12.) ]

Solving an equation (or a system) and using the result in further calculations

Solve[{2  (x^2) - 3  (y^2) == 1, (x^2) + (y^2) == 1}, {x, 
        y}]

Nothice that this doesn't actually assign any of these values to x or y:  These are simply a set of rules allowing you to assign these solutions to x and y.

x

To actually use these solutions, try the following:

systemSolutions = 
      Solve[{2  (x^2) - 3  (y^2) == 1, (x^2) + (y^2) == 1}, {x, 
          y}]

This assigns the set of solutions "rules" to the name "systemSolutions"

systemSolutions

Now, we can plug ALL of those solutions into an expression in x and y at the same time:

Sin[x] - Cos[y] /. systemSolutions

Or, you can get numerical values for these by:

Sin[x] - Cos[y] /. systemSolutions // N

Evaluating functions

First, define the function:

volumeCylinder[radius_, height_] := π (radius^2) 
        height

Notice the underscore (_) after the independent variables on the left. These tell Mathematica that anything can be substituted in place of them on the right (no underscores on the right).  Notice how I use descriptive variable names in the definition; it makes it a bit longer, but it makes it easier later to be clear what the function actually does. (You could add some parenthesis if the long variable names bother you.)

Now, you can call this function:

volumeCylinder[4, 12]

By putting a decimal point on one or both of these numbers, you can tell Mathematica to use decimal approximations:

volumeCylinder[4. , 12]

It also works symbolically:

volumeCylinder[a, 7 (Sqrt[ 2])]

Or you can plot it:

Plot[volumeCylinder[r, 5], {r, 0, 4}]

Plot3D[volumeCylinder[r, h], {r, 0, 5}, {h, 0, 5}]

You can also use it in other commands:

∫volumeCylinder[r, h] \[DifferentialD]r

(∂_r) volumeCylinder[r, h]

However, be careful of the following:

(∂_r) volumeCylinder[2, 4]

This just took the derivative of a constant function (π(2^2) 4) rather than first taking the derivative and then evaluating it at (2,4).  To do the latter, try:

(∂_r) volumeCylinder[r, h] /. {r -> 2, 
        h -> 4}

Calculus operations

Derivatives

Functions of a single variable:

If the function is defined in advance:

f[x_] := Log[Sin[x]]

Then you can use the shortcut form:

f'[x]

f'[(π/3)]

This form can be used if you don't need to define the function in advance.

(∂_x) (Log[Sin[x]])

Multiple derivatives can be done as follows:

f''[x]

Notice that this is two apostrophes, not a quotation mark.

(∂_(x, x))(Log[Sin[x]])

You can also take derivatives symbolically:

(∂_x) (h[x] Sin[3  x])

Partial derivatives:

(∂_x) (3  Sin[2  x] - 5  Cos[3  x] - 
          y (E^x))

(∂_(x, y))(3  Sin[2  x] - 5  Cos[3  x] - 
          y (E^x))

(∂_x) (f[x, y, z] Cos[x y z])

Implicit derivatives:

Dt[(x^2) - (y^2) - 4, x]

Dt[(x^2) - (y^2) - 4, y]

Dt[y,x] is the derivative of y with respect to x (i.e., assumes y is dependent on x).

Differentials:

Dt[(x^2) (y^3)]

Dt[x] would be written as dx in standard mathematical notation.

Integrals

Warning:  Use the tool palette to enter the integral signs (with the associated dx).  Don't try to just type them in directly.

Indefinite integrals:

∫(x^3) Sin[x] \[DifferentialD]x

∫(E^(a t)) 
        Sin[b t] \[DifferentialD]t

Definite integrals:

(∫_0^π) (x^9) Sin[x] \[DifferentialD]x

(∫_1^b) Log[t] \[DifferentialD]t

Improper integrals:

(∫_1^∞) (a/(x^3)) \[DifferentialD]x

(∫_(-∞)^∞) 
            (1/(7 + (x^2))) \[DifferentialD]x

\(∫\_\(-2\)\%4\( 
            1\/\@\(b\ x\)\%5\) \[DifferentialD]x\)

Multiple integrals:

(∫_(-1)^1)(∫_(-(Sqrt[1 - (z^2)]))^((Sqrt[1 - (z^2)])))(∫_0^((Sqrt[1 - (y^2) - (z^2)])))(Sqrt[1 - (x^2) - (y^2) - 
                  (z^2)]) \[DifferentialD]x \[DifferentialD]y \[DifferentialD]z

Limits

Limit[(((x^2) - 7)/((x^3) - 7  x)), x -> (Sqrt[7])]

Limit[Sin[x]/x, x -> 0]

Limit[Sin[x]/(x ), x -> ∞]

Limit[(((1 + (3/(2  r))))^(4  r)), r -> ∞]

Check this one out:

Limit[(∑_(j = 1)^n)(Sin[π + ((π j)/n)] (π/n)), 
      n -> ∞]

Sums and series

Sums:

Enter this from the tool palette:

(∑_(n = 1)^∞) (1/(n!))

(∑_(n = 1)^∞) ((x^(a n))/(n!))

Taylor series:

Series[Sin[x], {x, 0, 11}]

Series[Sin[x], {x, (π/6), 5}]

Series[(((1 + x))^n), {x, 0, 5}]

To actually compute with these series, you must use:

Normal[Series[Sin[x], {x, 0, 11}]]

Useful algebra and matrix commands

Partial fractions:

Apart[((4  (x^9) - 3  (x^5) + (x^2) - 7  x + 1)/(4  (x^4) - (x^2)))]

Vector operations:

aVector = {1, 2, 3}; bVector = {-2, 4, -7};

Dot product

aVector . bVector

Magnitude

(Sqrt[aVector . aVector])

Cross product

aVector\[Cross]bVector

Matrix operations:

aMatrix=(({{1, a, 3}, {b, 0, c}, {4, 5, d}})); bMatrix=(({{1, 2}, {3, 4}}));cMatrix=(({{1, b}, {c, 2}}));

End commands that produce a matrix as output (Inverse, for example) with //MatrixForm so the answer looks like a matrix.

Matrix operations

bMatrix + 3  cMatrix  // MatrixForm

bMatrix . cMatrix  // MatrixForm

Notice that you use a standard period for matrix multiplication (the * or × will NOT give the correct answer).

Inverse

Inverse[aMatrix]  // MatrixForm

Determinant

Det[aMatrix]

Eigenvalues

Eigenvalues[cMatrix]

Eigenvectors

Eigenvectors[cMatrix]