Preface


This is a tutorial made solely for the purpose of education and it was designed for students taking Applied Math 0330. It is primarily for students who have very little experience or have never used Mathematica before and would like to learn more of the basics for this computer algebra system. As a friendly reminder, don't forget to clear variables in use and/or the kernel.

Finally, the commands in this tutorial are all written in bold black font, while Mathematica output is in normal font. This means that you can copy and paste all commands into Mathematica, change the parameters and run them. You, as the user, are free to use the scripts for your needs to learn the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the second course APMA0330
Return to Mathematica tutorial for the first course APMA0340
Return to the main page for the course APMA0340
Return to the main page for the course APMA0330

Simplify and Expand


The Collect command allows the user to direct Mathematica to collect like powers of a variable together. We begin with a simple mathematical example: Mathematica can help us write the expression \( yx^2+x^2+3y^2 x+xy^4+(x+1+y)^2. \) Upon expansion we see this is equivalent to :
Expand[ y*x^2 + x^2 + 3 y^2 x + x y^4 + (x+1+y)^2 ]
Out[1]= 1 + 2 x + 2 x^2 + 2 y + 2 x y + x^2 y + y^2 + 3 x y^2 + x y^4
We can collect terms of like x powers as follows:
Collect[ 1 + 2 x + 2 x^2 + 2 y + 2 x y + x^2 y + y^2 + 3 x y^2 + x y^4 , x]
Out[1]= 1 + 2 y + y^2 + x^2 (2 + y) + x (2 + 2 y + 3 y^2 + y^4 )
We can also have Mathematica collect powers of y:
Collect[ 1 + 2 x + 2 x^2 + 2 y + 2 x y + x^2 y + y^2 + 3 x y^2 + x y^4 , y]
Out[2]= 1 + 2 x + 2 x^2 + (2 + 2 x + x^2) y + (1 + 3 x ) y^2 + x y^4

Example: Suppose that in a region of wilderness, the function \( f(x,y) = 1 + x^2 - 2 y + x y + 10 y^2 - 7 x y^2 + x^2 y^2 + 2 y^3 + x y^3 + x^2 y^3 \) models the topography where f(x,y) is the height and x and y indicate the location. Suppose you want to create a simple formula for the height of the wilderness as a function of y at several points x = a. We can accomplish this most easily by using Mathematica to collect the y terms.

 

 

Return to Mathematica page

Return to the main page (APMA0330)
Return to the Part 1 (Plotting)
Return to the Part 2 (First Order ODEs)
Return to the Part 3 (Numerical Methods)
Return to the Part 4 (Second and Higher Order ODEs)
Return to the Part 5 (Series and Recurrences)
Return to the Part 6 (Laplace Transform)
Return to the Part 7 (Boundary Value Problems)