(*III.GRAPHICS:TOPICS:Two-dimensional Three-dimensional and color Two-dimensional:Main functions:Plot,PlotRange,Show Plot[f,{x,xmin,xmax}] generates a plot of f as a function of x from xmin to xmax.Plot[{f1,f2,...},{x,xmin,xmax}] plots several functions fi.PlotRange is an option for graphics functions that specifies what points to include in a plot.Show[graphics,options] displays two-and three-dimensional graphics,using the options specified.Show[g1,g2,...] shows several plots combined.Use with Evaluate for complicated functions Dashing of lines Dashing[{r1,r2,...}] is a two-dimensional graphics directive which specifies that lines which follow are to be drawn dashed,with successive segments of lengths r1,r2,... (repeated cyclically).The ri is given as a fraction of the total width of the graph.*)

plo[n_]:=Plot[Sin[n x]/x,{x,-2,2},PlotStyle->Dashing[{0.01*n,0.02}]]

Show[Table[plo[n],{n,1,3}],PlotRange->{-1,3}]
(*Note:to plot Tables of more complex functions,use Plot[Release[Table[…]]]*)

(*AxesLabel->{“x”,“y”} will label each axes.Greek letters:α,etc.(in Notebook can copy from pallet)
*)

(*Plotting discrete data points:ListPlot[{y1,y2,...}] plots a list of values.The x coordinates for each point are taken to be 1,2,....ListPlot[{{x1,y1},{x2,y2},...}] plots a list of values with specified x and y coordinates. *)

list=Table[Sin[i/50.]+.1*Random[],{i,200}];ListPlot[list,Joined->True]

(*Parametric plot:ParametricPlot[{fx,fy},{t,tmin,tmax}] produces a parametric plot with x and y coordinates fx and fy generated as a function of t.ParametricPlot[{{fx,fy},{gx,gy},...},{t,tmin,tmax}] plots several parametric curves.*)
x[phi_]:=Cos[phi];y[phi_]:=Sin[phi];
ParametricPlot[{x[phi],y[phi]},{phi,0,2Pi}]

Clear[r];r=1-.9phi;x[phi_]:=r Cos[phi];y[phi_]:=r Sin[phi];
spir=ParametricPlot[{x[phi],y[phi]},{phi,0,20Pi},PlotLabel->"spiral"]

(*if we like what we see and want to create,e.g.a postscript file,t.ps*) disp:=Export["t.ps",#,"EPS"]&
(*now disp[spir] will create t.ps,as a GOOD postscript*) 
(*Graphics Primitives:Line[{pt1,pt2,...}] is a graphics primitive which represents a line joining a sequence of points.Point[coords] is a graphics primitive that represents a point.Circle[{x,y},r] is a two-dimensional graphics primitive that represents a circle of radius r centered at the point x,y.Circle[{x,y},{rx,ry}] yields an ellipse with semi-axes rx and ry.Circle[{x,y},r,{theta1,theta2}] represents a circular arc.Polygon,etc. –use with Graphics,similar to Arrow;HW:give graphic examples*).

Graphics[{Circle[{0,0},1],Circle[{0,0},{4,2}]}]

(*COMPLEX NUMBERS*)

i=I;

z=2+i;Show[Graphics[{PointSize[Large],Point[{Re[z],Im[z]}]}],PlotRange->{{-2,3},{-2,3}},GridLines->Automatic]

sol=Solve[w^2==-1,w]

roots={Re[w],Im[w]}/.sol

Show[Graphics[{PointSize[Large],Point/@roots}],PlotRange->{{-2,3},{-2,3}},GridLines->Automatic]

sol=Solve[w^25==-1,w];roots={Re[w],Im[w]}/.sol;Show[Graphics[{PointSize[Large],Point/@roots}],PlotRange->{{-2,2},{-2,2}},GridLines->Automatic]

sol=NSolve[w^25-w+w^2==-1,w];roots={Re[w],Im[w]}/.sol;Show[ListPlot[roots],PlotRange->{{-2,2},{-2,2}},GridLines->Automatic,AxesLabel->{"Re","Im"}]

Show[%,AspectRatio->1]

(*PLOTTING SOLUTIONS OF ODE*)

Clear[x,y];DSolve[{D[y[x],x]==x,y[0]==1},y[x],x]

sol=%[[1]]

Plot[y[x]/.sol,{x,0,1}]

(*2nd order Newtons eq-n with Hooks force;m=1=k*)

Clear[x,p,t];eqs={D[x[t],t]==p[t],D[p[t],t]==-x[t]-.4p[t]}

ic={x[0]==1,p[0]==0}

alleqs=Join[eqs,ic]

sol=DSolve[alleqs,{x[t],p[t]},t]

sol=%[[1]]//Chop

Plot[x[t]/.sol,{t,0,15},PlotRange->{-.75,1}]

ParametricPlot[{x[t],p[t]}/.sol,{t,0,40},AxesLabel->{x,p},PlotLabel->"phase portrait"]

(*Advanced:3-Dimensional graphics and colors"Plot3D[f, {x, xmin, xmax}, {y, ymin, ymax}] generates a three-dimensional plot of f as a function of x and y
"

Color:"RGBColor[red, green, blue] is a graphics directive which specifies that graphical objects which follow are to be displayed, if possible, in the color given." (“knows” main colors,Red,Blue,etc.*)

(*in 2-D*)
Plot[{Sin[x],Cos[x]},{x,0,5},PlotStyle->{Red,Green}]
(*HW:try this*)

?Plot3D

Clear[r]; r=Sqrt[x^2+y^2];
Plot3D[Sin[r]/r,{x,-13,13},{y,-13,13},PlotRange->All]

Plot3D[{Sin[r]/r,2-Sin[r]/r},{x,-13,13},{y,-13,13},PlotRange->All]

Show[%,ViewPoint->Front]

?ParametricPlot3D

cone=ParametricPlot3D[{Cos[u]*v,Sin[u]*v,1-v},{u,0,2*Pi},{v,0,1},PlotPoints->{60,12},ColorFunction->Hue]

sphere=ParametricPlot3D[{Cos[u]*Sin[v],Sin[u]*Sin[v],Cos[v]},{u,0,2*Pi},{v,0,Pi},PlotPoints->{60,12}]

(*ALTERNATIVES TO 3D*)

?DensityPlot

?r

DensityPlot[-Sin[r]/r,{x,-13,13},{y,-13,13},ColorFunction->Hue,PlotPoints->50,PlotRange->All]

DensityPlot[Sin[r]/r,{x,-13,13},{y,-13,13},ColorFunction->Hue,PlotPoints->100,PlotRange->All]

?ContourPlot

ContourPlot[-Sin[r]/r,{x,-13,13},{y,-13,13},PlotRange->All]

ContourPlot[-Sin[r]/r,{x,-13,13},{y,-13,13},PlotRange->All,ContourShading->False]

(*pendulum; x angle, p -momentum*)
Clear[u,e,p];
u=1-Cos[x](*pot. energy*);
e=u+p^2/2 (*full energy*)

ContourPlot[e,{x,-2 Pi,2 Pi},{p,-3,3},ContourShading->False,ContourLabels->All, AspectRatio->.4
]

(*IMPLICIT PLOT-from ContourPlot;*)ContourPlot[x^2+y^2==1,{x,-1,1},{y,-1,1}] (*circle*)

ContourPlot[{(x^2+y^2)^2==x^2-y^2,(x^2+y^2)^2==2 x y},{x,-1,1},{y,-1,1}] (*2plots with different styles-see output below.ContourPlot3D-similar*)

(*DISCRETE PLOTS*)

chesslist=Table[If[EvenQ[x+y],-1,1],{x,8},{y,8}]

MatrixPlot[-chesslist]

(*IMAGE as ARRAY of NUMBERS*)

lena=Import["ExampleData/lena.tif"]

Binarize[%]

im=ImageData[%];

im[[50]]//Short

MatrixPlot[im,ColorFunction->"Monochrome"]

A=Table[1,{3},{3}]

imc=ListConvolve[A,im];MatrixPlot[imc,ColorFunction->"Monochrome"]

imb=ListDeconvolve[A,imc];MatrixPlot[imb]

(*Real Image from BBC 4/25/2014*)

nova=Import["http://web.njit.edu/~vitaly/114/bbc-supernova.jpg"]

bw=Binarize[nova]

im=ImageData[bw];MatrixPlot[-im]