Important! ​​Click "Make Your Own Copy" in the black ribbon above to make this document interactive. You will also need to be logged into Wolfram Cloud​​​​
SCCC Mathematica Tutorial, © 2007-2020, Seattle Central Community College Math Dept., contact: Greg.Langkamp@seattlecolleges.edu
Version 1.9/ March 2020

Lesson 3 Basic Algebra

3.1 Basic input of algebraic expressions

Variables can be represented by single letters or multiple characters. For example
x,y,Y,cost,speed,andProfit,
are all acceptable names for variables in Mathematica . Keep in mind that Mathematica is case sensitive, so it will treat
xandX
as two different variables. The following rules will help you construct algebraic expressions.
Implied multiplication​If you want to multiply a number times a variable, say 5 times
x
in Mathematica , you just type in
5
x
. On the other hand, if you want to multiply two variables, say
x
times
y
, use an asterisk to explicitly indicate multiplication (i.e. x*y). If we enter xy instead of x*y, then Mathematica interprets these two adjacent letters as a single, multi-character variable called "
x
y
", rather than as the product of the two separate variables
x
and
y
. [Note: As an alternative to using an asterisk for multiplication, you can indicate multiplication by putting a space between the two variables: e.g., use x y instead of xy].
Parentheses vs.Square Brackets​You have seen that square brackets are used to enclose input arguments in both commands and functions. This is the only place in Mathematica where square brackets are allowed. Therefore, when entering a mathematical expression you must use parentheses for all grouping. You cannot use square brackets for grouping the way you do when writing math by hand. So, for example, in Mathematica
5(x+3(x-2))
cannot be entered as
5[x+3(x-2)]
.
Standard vs. Traditional Form​Mathematica has two formats available for displaying algebraic output. They are called StandardForm and TraditionalForm. The default form is StandardForm. The most noticeable aspect of this form is that polynomial expressions are displayed in ascending powers of the variable. So if you enter
2
x
+3x+5
, Mathematica will automatically display it as
5+3x+
2
x
. Execute the line below to see how this works.
x^2+3x+5
If you prefer to have polynomials displayed in descending powers of the variable then you can add the command TraditionalForm to the input line. Note that the command TraditionalForm is just one word, no space.
x^2+3x+5//TraditionalForm
Exercise 3.1 A
Enter the expression
5x+10+7xy
. Use an asterisk to indicate
x
times
y
.
​
Answer to Exercise 3.1A
To enter this expression we type:
5x+10+7x*y
. [Or you can use 5x+10+7x y]
5x+10+7x*y
Exercise 3.1 B
Enter the expression
2
x
-3x+5
3
(x-4)
​
Answer to Exercise 3.1B
(x^2-3x+5)/(x-4)^3
(x^2-3x+5)/(x-4)^3//TraditionalForm

3.2 Assigning a value to a variable (and clearing a variable)

If we wish to assign the value 10 to the variable
x
we just enter
x=10
. Once the assignment is made it will remain in Mathematica's memory until either there is a reassignment or the variable is "cleared". ​​​Look at the input cell below. Observe that the letter
x
is currently blue . Unassigned variables and functions are always displayed in a color. However, as soon as you evaluate the cell, the
x
will change to black. This is Mathematica's way of alerting you that
x
is no longer a symbolic variable, but instead equals a particular number.
x=10
We can check the current value of
x
by simply entering it and evaluating the cell.
x
Now if we use
x
in an expression, Mathematica will automatically substitute our assigned value (i.e. 10) for
x
.
3x+4
If we redefine
x
to be a different value, then the original value is replaced with this new value.
x=100
Let's check that the value of
x
has changed.
x
3x+4
​
The Clear command.
We can use the Clear command to clear
x
of any value, so that we can use it as a symbolic variable again. As you evaluate this command in the next input cell notice how all of the
x
's (up and down the page) become blue again.
Clear[x]
We can check that
x
no longer has a value assigned.
x
The Clear command can clear more than one variable at a time. Execute the next set of inputs to see how this works.
a=1
b=2
a+b
Clear[a,b]
a+b
☑ It turns out that the most common error that new users make is to forget that they have assigned a value to a variable. Mathematica's color coding scheme is designed to help avoid this error.
Exercise 3.2A
Assign the value
2π
3
to the variable
m
. Then find a decimal approximation for
m+3
.
​
​
Answer to Exercise 3.2A
m=2π/3
N[
m+3
]

3.3 The Expand and Factor commands

Please evaluate the following command, before continuing with this section.
Clear[m,x]
The principal use of the Expand command is to "multiply out" products of polynomial expressions.
◼
  • Use the Expand command to expand the product
    (x+2)(x-3)
    .
    ​
    Note no asterisk for multiplication is needed here since we are using parentheses to separate the factors.
  • Expand[(x+2)(x-3)]
    ◼
  • Use the Expand command to expand the expression
    7
    (x-5)
  • Expand[(x-5)^7]
    ​
    Exercise 3.3 A
    Answer to Exercise 3.3A
    Exercise 3.3 B
    Answer to Exercise 3.3B
    ​
    Exercise 3.5 A
    Answer to Exercise 3.5A
    ​
    ​
    Exercise 3.6 A
    Answer to Exercise 3.6A