Mathematica Symbolics

by
K. D.  Stroyan
University of Iowa

copyright 2007 by Keith Stroyan - All rights reserved.

Review: Closed and Open Mathematica Cells

The NoteBook MmaNtBkCells introduces you to use of cells.

To open a closed cell, use your mouse to position the cursor over the dark arrowhead and click the button on the mouse twice rapidly.  (This is called "double clicking.")  When you are done looking at a section, you can position the cursor at the far right bracket again and double click to close that section.

Open the cell containing "Notebook Overview" now.  Then close this cell.

Notebook Overview: What's expected?

This NoteBook introduces you to symbolic computations in Mathematica.  Modern scientific programming languages can do the symbolic operations of high school math, such as factoring polynomials, putting rational expressions on a common denominator and simplifying trig expressions.  They can also do the symbolic computations of calculus, as we shall see throughout the course.

The only requirement of the NoteBook is for you to work the Practice Exercise.  The remaining computations are only to give you a quick tour of some of the symbolic computations in Mathematica.

References to the Text

This NoteBook goes with Chapter 1 of the text.

High School Algebra with Mathematica

Most of what you have learned in algebra like factoring, combining algebraic fractions, solving polynomial equations, and working with radicals can all be done with Mathematica.

Polynomial computations

If a variable like  x  is not assigned any value, Mathematica can work with a combination of terms involving  x  as a symbolic expression.  (The command Clear[x] makes sure  x  is not assigned any value.)

To define this expression as a polynomial  p[x]  we use :=  rather than   =  because p is a function of x.  The function  p  may take on many different values, depending on the value of  x  and the  :=  tells Mathematica to go back to the formula defining  p  each time it needs its value.  If  x  is not assigned a value,  p  is treated as a symbolic expression.

Enter the next computation to see that Mathematica recognizes  p[x]  as a symbolic expression.

Clear[x,p];
p[x_]:=(x^4)+3 (x^3)-16 (x^2)-9 x+9;
Print["p[x] = ",p[x]];

Now enter the next cell below to see the polynomial factored.

Factor[p[x]]

Enter the cell below to see the exact roots of the polynomial.

Solve[p[x]==0,x]

Remember that using the N command will give you decimal approximations to the solutions that may be more useful than the above exact form.

N[Solve[p[x]==0,x]]

Numerical solutions can also be obtained with the NSolve[.] command as follows.

NSolve[p[x]==0,x]

Practice Exercise

Now you try.  Open the Basic Input Palette under the File Menu.  Define the polynomial

p[x] = (x^5)-(x^4)-13 (x^3)+13 (x^2)+36 x-36

using correct Mathematica function definition: p[x_] := ???  Then Factor p[x]  and find its roots.

Rational Expressions

The sum  1/2 + 1/3  is NOT equal to the sum of the numerators over the sum of the denominators, 2/5.  Rather, we need to put both on a common denominator, 3/6 + 2/6 and then add numerators.

<Enter> the computation in the cell below to see Mathematica  add:

(1/2)+(1/3)

Let's see what Mathematica thinks of the first computation.  Mathematica uses single = for replacement.  That is,  a = b means, replace a by b.  Mathematical equality is represented by ==.  Let's see if Mathematica thinks both computations are equal:

<Enter> the next computation:

(2/5)==(5/6)

The sum of two algebraic fractions is also done by putting the expressions on a common symbolic denominator, but Mathematica will need to be told to combine things.

Clear[x,r];
r[x_]:=(1/(x-2))-(5/(x+5))
r[x]

Together[r[x]]

Clear[x,r];
r[x_]:=(1/(x-2))-(5/((x+5) (x-2)))
r[x]

Together[r[x]]

Practice Exercise

Try this out.  Define the function  r[x_] := 1/(x-1) - 1/(x+1) and use Together[.] to put it on a common denominator.  (You can write this (1/(x-1))-(1/(x+1)) by using the Basic Input Palette.)

Basic High School Trig

The most important things you need to recall (or re-learn) from high school trig are the identities:

((Sin[x])^2)+((Cos[x])^2) = 1

Sin[x + y] = Sin[x] Cos[y] + Cos[x] Sin[y]

Cos[x + y] = Cos[x] Cos[y] - Sin[x] Sin[y]

Mathematica knows these identities.  See for yourself by <Enter>ing the following computations:

Clear[x,y,pythagorean,addSin,addCos]
pythagorean=((Sin[x])^2)+((Cos[x])^2)
addSin=Sin[x] Cos[y]+Cos[x] Sin[y]
addCos=Cos[x] Cos[y]-Sin[x] Sin[y]

Simplify[pythagorean]

Simplify[addSin]

Simplify[addCos]

Practice Exercise

Now you try.  Simplify the quantity  (Tan[x])^2 + 1

Example 1.7 & Verify Your Work in Exercise 1.4.2 & 3

Work through these computations and compare them to your paper and pencil work from Chapter 1, Exercise 1.4.2 & 3.  The case n=3 is worked in Example 1.7 of the text.

In calculus, we will want to expand the expression  (x + Δx)^n  for  n = 1, 2, 3, 4, ...  In fact, we want to simplify the quotient expression ((x+Δx)^n - x^n)/Δx.)  Here's how with Mathematica:

First, we clear the variables and functions we will need.  Then define the function x^n and look at the result. <Enter> the computation now.

Clear[x,Δx,n,f,q];
f[x_]:=(x^n);
f[x]

Let's see the general expression at the input  x+Δx: <Enter> the computation now.

f[x+Δx]

Now fix  n = 1 and look at  p[x+dx]: <Enter> the computation now.

n=1
f[x+Δx]

This wasn't very interesting.  Let's look at the square. <Enter> the computation now.

n=2
f[x+Δx]

You may recall the formula  (((a+b))^2)=(a^2)+2 ab+(b^2).  Mathematica can do this expansion with our variables: <Enter> the computation now.

Expand[f[x+Δx]]

You may or may not recall the formula  (((a+b))^3)=(a^3)+3 (a^2) b+3 a (b^2)+(b^3).  Mathematica can do this expansion: <Enter> the computation now.

n=3
f[x+Δx]
Expand[f[x+Δx]]

Example 1.7 simplifies the formula  f[x+Δx] - f[x]  and then divides by  Δx  and simplifies again.  <Enter> the computation now. (n is still 3 from the last computation.)

q[x_]:=Simplify[((Expand[f[x+Δx]]-f[x])/(Δx))]
q[x]

This last expression has an obvious limit as Δx  tends to zero, the  3(x^2) is un-changed and the other terms go to zero, but Mathematica can compute this:

Limit[q[x],Δx->0]

Mathematica still knows the general formula for the quotient  q[x], but it can't simplify the expression with a general  n  as the power.   <Enter> the next computation.

Clear[n]
q[x]

n=4
f[x+Δx]
Expand[f[x+Δx]]
q[x]
Limit[q[x],Δx->0]

n=5
f[x+Δx]
Expand[f[x+Δx]]
q[x]
Limit[q[x],Δx->0]

Modify this computation to compute the difference quotient when  n=2  as in Exercise 1.4.2: (you can Copy, Paste and modify the previous computation.)

Mathematica can still compute numerical values of  f[x].  Enter the next computation.

x=1
f[x]

To make  f[x]  a symbolic polynomial again, we must "clear" the variable by entering the next computations.

Clear[x];
f[x]

Mathematica can even do the symbilic limit in the general case.

Clear[n];
f[x]
q[x]
Limit[q[x],Δx->0]

A Preview of Symbolic Calculus with Mathematica

Limits

Clear[x,Δx,n];
Limit[(((((x+Δx))^n)-(x^n))/(Δx)),Δx->0]

Clear[x,f,Δx];
f[x_]:=(1/x);
Limit[((f[x+Δx]-f[x])/(Δx)),Δx->0]

Clear[x,f,Δx];
f[x_]:=(Sqrt[x]);
Limit[((f[x+Δx]-f[x])/(Δx)),Δx->0]

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

Limit[((1-Cos[x])/x),x->0]

Limit[((1-Cos[x])/(x^2)),x->0]

Derivatives

Clear[x,f];
f[x_]:=(x^3);
f[x]
f'[x]

Clear[x,f,p];
f[x_]:=(x^p);
f[x]
f'[x]

Clear[f,x];
f[x_]:=Sin[x];
f[x]
f'[x]

Clear[f,x,n,b];
f[x_]:=(Sqrt[Log[x] (Sin[x]+(x^n)-(3/x)) (b^x)]);
f[x]
f'[x]

Integrals

∫(x^3)\[DifferentialD]x

(∫_0^1)(x^3)\[DifferentialD]x

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

Differential Equations

DSolve[x'[t]==x[t],x[t],t]

??DSolve

Infinite Series

(∑_(k=1)^∞)(1/(k^2))

Series[Exp[x],{x,0,7}]

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

Series[Cos[x],{x,0,7}]

??Series