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
Version 1.9/ March 2020
Lesson 3 Basic Algebra
Lesson 3 Basic Algebra
3.1 Basic input of algebraic expressions
3.1 Basic input of algebraic expressions
Variables can be represented by single letters or multiple characters. For example are all acceptable names for variables in Mathematica . Keep in mind that Mathematica is case sensitive, so it will treat as two different variables. The following rules will help you construct algebraic expressions.
x,y,Y,cost,speed,andProfit,
xandX
Implied multiplicationIf you want to multiply a number times a variable, say 5 times in Mathematica , you just type in . On the other hand, if you want to multiply two variables, say times , 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 "", rather than as the product of the two separate variables and . [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].
x
5
x
x
y
x
y
x
y
Parentheses vs.Square BracketsYou 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 cannot be entered as .
5(x+3(x-2))
5[x+3(x-2)]
Standard vs. Traditional FormMathematica 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 +3x+5, Mathematica will automatically display it as . Execute the line below to see how this works.
2
x
5+3x+
2
x
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 . Use an asterisk to indicate times .
5x+10+7xy
x
y
Answer to Exercise 3.1A
To enter this expression we type: . [Or you can use 5x+10+7x y]
5x+10+7x*y
5x+10+7x*y
Exercise 3.1 B
Enter the expression -3x+5
2
x
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)
3.2 Assigning a value to a variable (and clearing a variable)
If we wish to assign the value 10 to the variable we just enter . 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 is currently blue . Unassigned variables and functions are always displayed in a color. However, as soon as you evaluate the cell, the will change to black. This is Mathematica's way of alerting you that is no longer a symbolic variable, but instead equals a particular number.
x
x=10
x
x
x
x=10
We can check the current value of by simply entering it and evaluating the cell.
x
x
Now if we use in an expression, Mathematica will automatically substitute our assigned value (i.e. 10) for .
x
x
3x+4
If we redefine to be a different value, then the original value is replaced with this new value.
x
x=100
Let's check that the value of has changed.
x
x
3x+4
The Clear command.
We can use the Clear command to clear 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 's (up and down the page) become blue again.
x
x
Clear[x]
We can check that no longer has a value assigned.
x
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 to the variable . Then find a decimal approximation for .
2π
3
m
m+3
Answer to Exercise 3.2A
m=2π/3
N[
m+3
]3.3 The Expand and Factor commands
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 . Note no asterisk for multiplication is needed here since we are using parentheses to separate the factors.
(x+2)(x-3)
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