Symbolic and Numeric Calculations
File Input and Output

Mathematica  has a powerful array of functions that solve equations symbolically and ways to simplify expressions.  Many people use Mathematica because it removes the tedium of doing algebra with pencil and paper---and perhaps more importantly it doesn't make errors!  However, one frustrating aspect is getting Mathematica to represent an expression in exactly the form you desire.  Sometimes it is possible with patience, practice, and skill---and sometimes you have to give up and accept that the form of the expression will not be ``neat and compact.''

Operations on Polynomials, Rational Expressions, and Simplification of Expressions

A good way to gain familiarity with Mathematica's operations to do symbolic algebra is to look though the categories in the Built-in Functions section in the Help Browser.  Look though the names of functions  under Algebraic Computation--they have names that are fairly indicative of their purpose.

PaulENomeal = (1 + 2a + 3x + 4z)^4

FatPEN = Expand[PaulENomeal]

Factor[FatPEN]

PaulinX = Collect[FatPEN,x]

The coefficient of (x^2)

Coefficient[PaulinX,x,2]

Rewrite as a polynomial in x, but simplify the coefficients individually

PaulSpiffedUp = Sum[
Simplify[Coefficient[PaulinX,x,i]]x^i, {i,0,20}]

Simplify[PaulSpiffedUp]

Rational Expressions

RashENell =(((x+y))/((x-y))) +  (((x-y))/((y+x)))

Apart[RashENell]

Together[RashENell]

Apart[Together[RashENell]]

Numerator[Together[RashENell]]

Simplify[RashENell]

Factor[RashENell]

Simplfiying Expressions with Square Roots

One common hurdle is getting Mathematica  to remove roots:

RootBoy = (Sqrt[(((x+y))^2)])

Simplify[RootBoy]

Note in the following statement that "x ∈ Reals" means "x is a real number" and "&&" is the "Logical And" operator.

Simplify[RootBoy, x∈ Reals && y ∈ Reals]

Simplify[RootBoy, x≥ 0 && y  ≥ 0]

Brute force; clever , but not a good idea follows:

RootBoy/.Sqrt[(expr_)^2]-> expr

Calculus

AMessyExpression = ((Log[x Sin[x]])/(1/x))

Limit[AMessyExpression,x->0]

DMess = D[AMessyExpression,x]

Integrate[DMess,x]

DefInt1 =Integrate[DMess,{x,0,E}]

(AMessyExpression/.x->e) - (AMessyExpression/.x->0)

DefInt2 =(AMessyExpression/.x->E) - Limit[AMessyExpression,x->0]

DefInt1
DefInt2
DefInt1 == DefInt2

Integrate[Sin[x]/Sqrt[(x^2 + a^2)],x]

Integrate[((Sin[x])/(Sqrt[(a^2)+(x^2)])),x,Assumptions->Re[a^2]>0]

UglyInfiniteIntegral = Integrate[Sin[x]/Sqrt[(x^2 + a^2)],{x,0, ∞},Assumptions->Re[a^2]>0]

N[UglyInfiniteIntegral/.a->1]

Taylor Expansions

Now we will introduce the Taylor expansion capabilities in Mathematica:

Series[AMessyExpression,{x,0,4}]

FitAtZero = Series[AMessyExpression,{x,0,4}]//Normal

Plot[{AMessyExpression,FitAtZero},{x,0,3},PlotStyle->{{Thickness[0.02],Hue[1]},{Thickness[0.01],Hue[0.5]}}]

Solving Equations

TheEquation = a x^2 + b x + c

Note the use of Equal (==) rather than Set (=) in the following; using "=" will produce an error message.

TheZeroes = Solve[TheEquation ==0,x]

Note that the roots are given as Rules. Now we ask Mathematica to verify that the solutions it found are indeed roots to the specified equation. Here is a prototypical example of using Replace (/.) to accomplish this:

TheEquation/.TheZeroes

Simplify[TheEquation/.TheZeroes]

More examples of using Solve:

a[i_] := i+1

TheQuinticEquation = Sum[a[i] x^i,{i,0,5}]

Solve[TheQuinticEquation==0,x]

Quad1 = a x^2 + y + 3
Quad2 = a y^2 +x + 1

Solve[{Quad1==0,Quad2==0},{x,y}]

Numerical Solutions

Integrate[Sin[ x]/Sqrt[(x^2 + a^2)],x]

Integrate[Sin[ x]/Sqrt[(x^2 + a^2)],{x,0,1}]

NIntegrate[(Sin[ x]/Sqrt[(x^2 + a^2)])/.a->1,{x,0,2 Pi}]

Plot[
NIntegrate[Sin[ x]/Sqrt[(x^2 + a^2)], {x,0,2 Pi}],{a,0,10},PlotStyle->Thick,BaseStyle->{Large,FontFamily->"Helvetica"}]

Plot[{AMessyExpression,FitAtZero},{x,0,3},PlotStyle->{{Thickness[0.02],Hue[1]},{Thickness[0.01],Hue[0.5]}}]

NSolve[AMessyExpression==0,x]

FindRoot[AMessyExpression==0,{x,.5,1.5}]

FindRoot[FitAtZero==0,{x,.5,1.5}]

FindRoot[AMessyExpression==0,{x,2.5,3}]

File Input and Output

This will show the directory (folder) to which files are currently being written or read.

Directory[]

AMessyExpression >> AFile.m

Clear[AMessyExpression]

<<Afile.m

The previous statement reads in the expression, but it is not assigned to its previous symbol

AMessyExpression

AMessyExpression  = << AFile.m

AMessyExpression

FilePrint["Afile.m"]

Close["ANewFileName"]

AFileHandle = OpenWrite["ANewFileName",FormatType->OutputForm]

RandomPairs=Table[RandomReal[{0,1},2],{i,10}]

Write[AFileHandle,RandomPairs]

FilePrint["ANewFileName"]

Write[AFileHandle,MatrixForm[RandomPairs]]

FilePrint["ANewFileName"]

Close[AFileHandle]

Using Packages

Fortunately, others have gone to the trouble of writing files full of useful stuff--and you can load this stuff into Mathematica for your very own use.  Some people produce useful stuff and you can buy it, which is nice if you find it valuable--and you can write stuff and gain value by selling it, which might be even more nice.
Mathematica comes with a group of Standard Packages, that you can load in to do special tasks.  The Package documentation can be found with the Helper Palette, available here.  For example, take a look at the specialized package Calendar:

<<Calendar`

DayOfWeek[{1929,9,30}]

DateList[]

CalendarChange[DateList[],Gregorian,Islamic]

DateString[CalendarChange[DateList[],Gregorian,Islamic]]