"MATHEMATICA"

A Short introduction to the Programm

N. Kadianakis

Note
Run "Mathematica" and then open this notebook (File-> Open ->"Mathintro.nb"). Run any comand in the notebook pressing "Shift+Enter" at the end of the line. Most of the commands have an obvious meaning. Try your own by changing some of the options in the commands, using Help if necessary.

Introduction

Every notebook is organised in cells which may contain commands (evaluatable cell) or simply text. These notes are writen in a notebook.

To run every command in the cell press  "Shift+Enter". Duble clicking  on the arrow at right  opes a fammilly of nested cells.

The whole manual of the programm is in the Help menu. You can copy and paste ready examples in your notebook and run them.

If you wand help  for a specific command  like "Plot" just type:?Plot.

The produced graphics can be copied and pasted in other  applications like word processors.

Algebraic Operations

(3+4)^2-2*(3+1)

4/5*3^4

N[Pi]

N[Sqrt[2],6]

N[(((Cos[(3/5)])/(Sin[(Sqrt[(2/3)])]))^(1/3))]

43!

Expand[(x-a)^3]

3 x+6 x

Functions of one variable

Definition of a function:

f[x_]:=Cos[x]Sin[x]

and using the defined function f[x] :

f[a+b]
Cos[a+b] Sin[a+b]

TrigExpand[f[a+b]]

Ploting  f[x]:

Plot[f[x], {x,-2,2}]

Options[Plot]

A function with a parameter:

g[n_,x_]=Sin[n x]

g[3,x]

Firs derivative with respect to x:

D[g[n,x],x]

Third  Derivative

D[g[n,x],{x,3}]

Integration :

Integrate[f[x],x]

or fro a ready palete (File->Palets->Basic Calculations->Calculus->Common Operations )

∫f[x] \[DifferentialD]x

Numerical Integration

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

NIntegrate[g[4,x], {x,0,1}]

Functions of many variables

f[x_,y_]=Sin[x y]

(∂_x)f[x,y]

Plot3D[f[x,y], {x,0,Pi},{y,0,Pi}]

Show[%,ViewPoint->{1,-2,-.5}]

Plot3D[f[x,y], {x,0,Pi},{y,0,Pi},PlotPoints->60,Mesh->False]

ContourPlot[f[x,y],{x,-4,4},{y,-4,4},PlotPoints->60]

ContourPlot[x^2+y^2,{x,-4,4},{y,-4,4},PlotPoints->60,ContourShading->False]

<<Graphics`ContourPlot3D`

ContourPlot3D[x^2+y^2-4 z^2,
 {x,-4,4}, {y,-4,4}, {z,-4,4},ViewPoint->{-3.260, 3.640, 1.910},Contours -> {1,10}, ContourStyle -> {{RGBColor[1,0,0]},
       {RGBColor[0,.8,1]}}]

Clear[v]

r[u_,v_]:={u,v,u^3-3u v^2}

ParametricPlot3D[Evaluate[r[u,v]],{u,-1,1}, {v,-1,1}]

Options[ParametricPlot3D]

We can integrate the height function of a surface to find the volume above a given level over a given rectangle:

Vector functions of one variable

Vector (x,y,z), Inner product length of a vector:

Clear[u,v]

v={1,2,-4};w={0,1,3}
v.w
(Sqrt[v.v])

r[t_]={Sin[2t],Cos[2t]}

r'[t]

Length of a curve:

(∫_0^(2 Pi))(Sqrt[r'[t].r'[t]]) \[DifferentialD]t

r''[t]
q[t_]={Sin[2t],Cos[3t]}

Evaluate[q[t],{t,2,2}]

ParametricPlot[
Evaluate[q[t],{t,0,2Pi}],AspectRatio->1]

elika[t_]:={Sin[t],Cos[t],t/2}

ParametricPlot3D[
Evaluate[elika[t],{t,0,4Pi}]]

Vector functions of many variables

Vector Fields

<<Graphics`PlotField`

P[x_,y_]=0.5 (y-1);
Q[x_,y_]=0.3 (x-0.5);

F[x_,y_]={P[x,y],Q[x,y]}

v=PlotVectorField[F[x,y],{x,-4,4},{y,-4,4},PlotPoints->20,Axes->True,ScaleFactor->None]

StreamPlot[F[x,y],{x,-4,4},{y,-4,4},Axes->True]

Restriction of a vector field on a curve:

x[t_]=3 Cos[t];
y[t_]=Sin[t];
r[t_]={x[t],y[t]};

cc=ParametricPlot[Evaluate[r[t],{t,0,2 Pi}],AspectRatio->Automatic,PlotStyle->{{Thickness[0.013],RGBColor[1,0,0.5]}}]

F[x[t],y[t]]

vectors=Table[{{x[t],y[t]},F[x[t],y[t]]},{t,0,2 Pi,Pi/16}];

bb=ListPlotVectorField[vectors,Frame->True]

Show[cc,bb]

PlotVectorField[{x,y},{x,-4,4},{y,-4,4},PlotPoints->10,Axes->True]

Parametric  Surfaces

Clear[u,v]

r[u_,v_]={u-v,v+u,u  v/3}

ParametricPlot3D[Evaluate[r[u,v],{u,-6,6},{v,-6,6}]]

Clear[F1,F2,G]

Electrostatic field of magnitute 1at A(-1,0)

F1[x_,y_]=(({x+1,y})/(((((x+1))^2)+(y^2))^(3/2)))

Electrostatic field of magnitute -1at B(1,0)

F2[x_,y_]=((-{x-1,y})/(((((x-1))^2)+(y^2))^(3/2)))

Their combination( sum)

G[x_,y_]=F1[x,y]+F2[x,y]

and their plots:

StreamPlot[F1[x,y],{x,-3,3},{y,-3,3}, Axes->True]

StreamPlot[F2[x,y],{x,-3,3},{y,-3,3},Axes->True]
StreamPlot[G[x,y],{x,-3,3},{y,-3,3}, Axes->True]