2301520 Fundamentals of AMCS
Basic Calculation

(*Excerpted from the Tutorial by Wolfram Research*) You normally interact with Mathematica through documents called notebooks. This tutorial is an example of a notebook. Notebooks can have many forms. But typically they consist of cells that can contain text, calculations, or graphics.

Cells are indicated by brackets on the right. This cell is a text cell. Input for Mathematica to evaluate goes in input cells.

To create a new input cell, just click outside an existing cell and start typing. When you have finished, press ⇧|⌤. Mathematica evaluates your input and puts the result in an output cell immediately underneath.

Here are sample calculations. Your cursor can be anywhere in the input cell when you press ⇧|⌤. The In[n]:= and Out[n]= labels are added automatically.

Section 1. Numerical Calculation

1.1 Arithmetic

1.2 + 2.3

2+3^4*5

1 2 3 4 5

1.2 Exact and Approximate Results

2549^2006

N[2549^2006]

1/2+1/3

1/2+1/3 //N

1/2

1./2

1+2./3

1.3 Some Mathematical Functions

Sqrt[2]

Sqrt[2]//N

100!

100!//N

Log[2]//N

Log[2,64]

Sin[Pi/6]

Tan[15 Degree]

1.4 Arbitrary-Precision Calculations

Pi

N[Pi]

N[Pi,1000]

1.5 Complex Numbers

Sqrt[-1]

I^2549//N

E^(2-3I)

Arg[E^(2-3I)]

Section 2. Building Up Calculations

2.1 Using Previous Results

2^3

%+7

%%*3

2.2 Making Lists of Objects

{2,1,2,3}

%^2+1

{1,2,3}-{1,4,9}

v={1,2,3}

v+(1/v)

2.3 Manipulating Elements of Lists

{2,1,2,4,6}[[2]]

{2,1,2,4,6}[[{2,1,5}]]

v={2,1,2,4,6}

v[[3]]=15

v

Section 3. Algebraic Calculations

3.1 Transforming Algebraic Expressions

Expand[(((1+x+y))^3)]

Factor[%]

Expand[(((1+x))^(5/2))]

Factor[%]
(1/2)+3 (x^2)+(x/(x-1))

Expand[%]

Together[%]

Expand[%]

3.2 Values for Symbols

(Sqrt[x+2(Sqrt[x-1])])+(Sqrt[x-2(Sqrt[x-1])])/.x->1.5

(x^10)+(y^10)/.x->1-y

(x^3)+(y^3)/.{x->1+a,y->1-a} //Expand

(x^3)+a (x^2)+b x+c/.x->x-(a/3) // Expand

x

x=1+y

(x^2)

x=.

x

3.3 Simplifying Algebraic Expressions

(1-x+3(x^2))+(3x-2)

Simplify[(x^3)+3(x^2)+3x+1]

Section 4. Symbolic Computation

4.1 Solving Equations

Solve[a (x^2)+b x+c==0,x]

{(x/.%[[1]] )+(x/.%[[2]]),(x/.%[[1]] )(x/.%[[2]])}//Simplify

Solve[a (x^3)+c x+d==0,x]//Simplify

Solve[{x+y==10,x-y==2},{x,y}]

NSolve[(2^x)==(x^2),x]

(2^x)-(x^2)/.%

4.2 Calculus

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

Limit[(x^x),x->0,Direction->-1]

D[ArcSin[x],x]

D[f[x]g[x],x]

D[(x^2)+Sin[x y],x]

∫((1+x)/(1-x))\[DifferentialD]x

(∫_0^∞)(E^(-(x^2)))\[DifferentialD]x

Integrate[x y,{x,0,1},{y,0,x}]

NIntegrate[(E^(-(x^2))),{x,0,1}]

Series[f[x],{x,a,5}]

4.3 Sums and Products

(∑_(n=1)^100)(1/n)

(∑_(n=1)^m)(n^4)

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

(∑_(n=1)^m)(1/n)-Log[m]/.m->10000//N

Limit[(∑_(n=1)^m)(1/n)-Log[m],m->∞]

(∏_(n=1)^∞)((4(n^2))/(4(n^2)-1))

G[x_]:=x^3/(x+2);
G[x]

Series[G[x],{x,0,10}] (* Maclaurin Series *)

Normal[%]

SeriesCoefficient[G[x],{x,0,n}]

Series[G[x],{x,1,10}] (* Taylor Series about 1 *)

Normal[%]

SeriesCoefficient[G[x],{x,1,n}]

Section 5 : Graphics

5.1 Two-Dimensional Plots

Plot[Tan[x],{x,-2π,2π}]

Plot[{(2^x),(x^2)},{x,-2,5}]

Plot[((Sin[x])/x),{x,-15,15}]

Options[Plot]

Plot[((Sin[x])/x),{x,-15,15},PlotRange->All,Frame->True,AxesLabel->{"x","((sin x)/x)"},PlotStyle->RGBColor[0,0,1]]

Plot[{(2^x),(x^2)},{x,-2,5},PlotStyle->{Directive[Red,Thick, Dashed], Blue}]

Plot[2+Sin[x],{x,-2π,2π}]

Plot[2+Sin[x],{x,-2π,2π},Ticks->{{-2π,-π,0,π,2π},Automatic},AxesOrigin->{0,0},PlotRange->{0,3}]

5.2 Two-Dimensional Parametric Plots

ParametricPlot[{Sin[2t],Cos[3t]},{t,0,2π}]

ParametricPlot[{Cos[t],Sin[t]},{t,0,2π}]

Options[ParametricPlot]

ParametricPlot[{Cos[t],Sin[t]},{t,0,2π},AspectRatio->Automatic]

ParametricPlot[{2Cos[t],Sin[t]},{t,0,2π}]

ParametricPlot[{2Cos[t],Sin[t]},{t,0,2π},AspectRatio->1]

5.3 Three-Dimensional Plots

Plot3D[Sin[x y],{x,0,π},{y,0,2π},AxesLabel->{"x","y","z"}]

Plot3D[Sin[x y],{x,0,π},{y,0,2π},AxesLabel->{"x","y","z"},ViewPoint->{0,0,2}]

Options[Plot3D]

5.4 Three-Dimensional Parametric Plots

Options[ParametricPlot3D]

ParametricPlot3D[{Cos[t],Sin[t],0.2t},{t,0,15π},Boxed->False,Axes->False,PlotPoints->250]

ParametricPlot3D[{Sin[u]Cos[v],Sin[u]Sin[v],Cos[u]},{u,0,π},{v,0,2π}]

ParametricPlot3D[{(4+Cos[v])Cos[u],(4+Cos[v])Sin[u],Sin[v]},{u,0,2π},{v,0,2π}]

5.6 List Plots

ListPlot[{0,1,4,9,16,25}]

Options[ListPlot]

ListPlot[{0,1,4,9,16,25},Joined->True]

ListPlot[{{0,0},{1,1},{2,4},{3,9},{4,16},{5,25}},Joined->True]

data3d=Table[Sin[x y],{x,0,π,(π/15)},{y,0,2π,(π/15)}];

ListPlot3D[data3d]

5.7 Two-Dimensional Contour Plots (Implicit Plots)

Plot3D[(x^2)-(y^2),{x,-4,4}, {y, -4,4}, AxesLabel->Automatic, ViewPoint->{0,-2,2}]

ContourPlot[(x^2)-(y^2),{x,-4,4}, {y, -4,4}, AxesLabel->Automatic]

ContourPlot[(x^2)-(y^2)==1,{x,-4,4}, {y, -4,4}]

ContourPlot[(x^2)-(y^2)==0,{x,-4,4}, {y, -4,4}]

Plot3D[(x^2)+(y^2),{x,-1,1},{y,-1,1}, AxesLabel->Automatic, ViewPoint->{0,-6,1}]

ContourPlot[(x^2)+(y^2),{x,-1,1},{y,-1,1}, AxesLabel->Automatic]

ContourPlot[(x^2)+(y^2)==1,{x,-1,1},{y,-1,1}]

ContourPlot[(x^2)+(y^2)==0.5,{x,-1,1},{y,-1,1}]