Lab 1:  Beginning to use Mathematica

In this lab, you will practise using the following commands:

    Factor[f]  - Factors the function f
    D[f, x]   - The derivative of a function f with respect to x
    Integrate[f, x]  - The indefinite integral of f with respect to x
    Integrate[f, {x,a,b}]  - The definite integral of f with respect to x between a and b

For example, let's start by factoring ((1 + x - 6  (x^2))/(1 - 2  x)).  Place the cursor in the following command and hit "enter" (or "shift-return"):

Factor[(1 + x - 6 x^2)/(1 - 2  x)]

In this equation, spaces are used to indicate multiplication and ^ is used to indicate a power (see "Short Guide to Mathematica Functions").  Mathematica should answer 1 + 3 x.  

You will get the same answer if you write the above fraction in a prettier form using the input palette (get this toolbox by clicking File -> Palettes -> BasicInput).  Again, place the cursor in the following command and hit enter (do this each time you see a command in bold):

Factor[((1 + x - 6  (x^2))/(1 - 2  x))]

Notice that these sentences are written in a different font than the input and output commands.  When entering a new line, you can change the format to text by clicking Format -> Style -> Text.  You can change it back to input by Format -> Style -> Input.

Also notice that each equation that Mathematica enters is given a number.  For example, the first command that you entered was labeled In[1], and the answer was labeled Out[1].  This is convenient because it allows us to refer to previous commands and manipulate them without retyping them.  For example, if Out[1] was 1 + 3 x, then we can factor (1+3 x) + 2 (x^2) by typing:

Factor[Out[1]  +  2 (x^2)]

As a short-cut, you can refer to n\(TraditionalForm\`\^th\) output as either Out[n] or %n

Factor[%1 +  2 (x^2)]

If you leave out the number, % refers to the last output.  For example, we can expand the previous result using:

Expand[%]

Mathematica really consists of two pieces of software:  the window (which we see) and the kernel (the brains behind it all).  The numbering of the input/output is done by the kernel.  When you close Mathematica, everything in the kernel is forgotten.  The next time that you open Mathematica, it will have forgotten what Out[1] was.  Mathematica starts counting your input/output all over again.

Now let's turn to derivatives.  First let's find ((d(4 (x^3)))/dx)by entering the following command:

D[4 (x^3), x]

Mathematica should give 12 (x^2), which is the derivative of 4 (x^3)with respect to x.  Similarly, we can find the derivative of Exp[4 (x^3)] with respect to x by entering:

D[Exp[4 (x^3)], x]

Anti-derivatives are found using the command Integrate.  For example, we can undo the above differentiation with respect to x using:

Integrate[12 (x^2) Exp[4 (x^3)], x]

The above represents an indefinite integral.  We can use the input palette to write this in a more familiar form:

∫12 (x^2) Exp[4 (x^3)] \[DifferentialD]x

We can also use Mathematica to find definite integrals.  For example, the area under the curve 1+(x^2) from x = 0 to 1 is given by:

Integrate[1 +  (x^2), {x, 0, 1}]

The term in curly braces {} represents the variable, the lower bound, and the upper bound, respectively.  Mathematica typically using curly braces {} to denote sets of information, square brackets [ ] to denote functions, and normal parentheses ( ) to denote terms that should be kept together.

If you are ever unsure of the notation to use, you can ask Mathematica for help, either by browsing the help (click Help -> Help Browser) or entering a question mark followed by the command of interest:

?Integrate

If you can't remember exactly what the name of a function was, you can use an * as a wildcard.  For example, the following returns all of the commands that start with Int:

?Int*

Practise factoring

Use Mathematica to factor the following equations:

	1 + 3  x + 2  (x^2)

	(1 - x^2)/(1 - x)

	2 - 5 x - 12 x^2
	 
Check all of the answers that Mathematica gives by hand.  Caution:  You have to place the cursor below the area of this text in order to get a new Input line (notice the blue lines down the right-hand side of the window, which tell you what Mathematica treats as a single group of lines).

Practise taking derivatives

Use Mathematica to take the derivatives of the following equations with respect to x:

	1 + 3  x + 2  (x^2)

	(1 - x^2)/(1 - x)

	 x^3 y^2

	 x^3 y[x]^2
	 
Check all of the answers that Mathematica gives by hand (use the fact that (1 - x^2)/(1 - x) factors).  In the last two cases, notice that Mathematica gives you different answers.  In the first case, Mathematica treats y as a constant parameter (we didn't tell it otherwise).  If, however, y depends on x, then we have to tell Mathematica that y is a function of x by writing y as y[x].

Practise finding indefinite integrals

Use Mathematica to take the anti-derivatives of the following equations with respect to x (i.e., find the indefinite integrals):

	1 + 3  x + 2  (x^2)

	(1 - x^2)/(1 - x)

	 x^3 y^2

	 x^3 y[x]^2
	 
Check all of the answers that Mathematica gives by hand (use the fact that (1 - x^2)/(1 - x) factors).  Again, Mathematica gives you different answers in the last two cases.  In the last case, Mathematica knows that y is a function of x, but it does not know what function of x it is, so it cannot evaluate the integral.

Practise finding definite integrals

Use Mathematica to find the integral of the following functions with respect to x between x=0 and x=1:

	1 + 3  x + 2  (x^2)

	(1 - x^2)/(1 - x)

	 x^3 y^2

	 4 (x^3)
	 
Check all of the answers that Mathematica gives by hand.

Try to stump Mathematica

Mathematica knows the derivative of any function that you can write -- no matter how complicated the function is, rules like the product rule and the quotient rule can be used to break the function down into smaller pieces, whose derivatives are known.

The same is not true about integrals.  Not all integrals can be solved, as there is no way to break down the integral of a complicated product into the product of smaller integrals.

Now, try to stump Mathematica!  Can you find a function whose derivative Mathematica does not know?  Can you find a function whose integral Mathematica does not know?