Post on 27-Dec-2015
MATHEMATICA – AN INTRODUCTION
R.C. VermaPhysics DepartmentPunjabi UniversityPatiala – 147 002
PART III- GRAPHICS
Two-dimensional plotsThree-dimensional plots.
List plotsContour plotsDensity plots
Parametric plotsParametric 3D-plots
Anmation
30. Two-Dimensional Plot
In[1]:= Plot[2x^3 –x^2 + 2, {x, -2, 2}]
30.1 Options for Plots: Setting Range, Scales, Labeling and PlotStylesThe vertical range can be specified using the PlotRange option.
This is useful for focusing on a significant feature of a graph.
Plots may be assigned to some variable.
In[2]:= p1=Plot[2x^3 –x^2 + 2,{x,-2, 2}, PlotRange->{-5, 5}]
In[3]:= p2 = Plot[ Exp[-0.1 x] Sin[x],{x,-5,5},PlotRange->{-2,2}]
In[4]:= Plot[Sin[x], {x, -Pi, Pi}, AxesLabel->{"x","Sin[x]"}]
ln[5]:= Plot[Sin[t], {t, 0, 2Pi}, AxesLabel -> {"Time","Amplitude"}, PlotLabel —> "Sine Wave"]
Plot[Sin[x], {x,0,2 Pi},PlotStyle->{RGBColor[1,0,1]}]
•
1 2 3 4 5 6
1 .0
0 .5
0 .5
1 .0
Mathematica also has ability to cope with poles.
In[6]:= Plot[ 1/Sin[x], {x, -Pi, Pi}]
31. Plotting two or more functions
ln[7]:= Plot[{ Exp[-0.1 x] Sin[x], x^2 -3x +1}, {x, -5, 5}]
plots exp[-0.1x] sin(x) and x^2 –3 x + 1 over the interval [-5, 5].
31.1 ShowThe Show[ ] command superimposes many plots. For instance, plotting some of the earlier named plots, type
In[8]:= Show[p1, p2]
In[38]:= Dashing 0.02,Line 0, 0, 2, 0, 2, 1, 0, 1, 0, 0
ShowGraphicsOut[38]= Dashing 0.02, Line 0, 0, 2, 0, 2, 1, 0, 1, 0, 0
Out[39]=
In[44]:= ShowGraphics GrayLevel.5,Thickness0.04,
Line 0, 0, 1, 1, 2, 0, 0, 0
Out[44]=
In[47]:= ManipulatePlotSinc x, x, 0, 10, c, 1, 5
Out[47]=
c
2 4 6 8 1 0
1 . 0
0 . 5
0 . 5
1 . 0
32. Three Dimensional PlottingFor creating three dimensional plots, use
Plot3D[ ]
The arguments of Plot3D[ ] are similar to those of the function Plot[ ].
In[9]:= Plot3D[Sin[x] Cos[y] , {x.-Pi.Pi}, {y.-2Pi.2Pi}]
In[9]:= Plot3D[Sin[x] Cos[y] , {x.-Pi.Pi}, {y.-2Pi.2Pi}, AxesLabel -> {x,y,z}, PlotPoints->40]
33 Evaluate commandA list of expressions can be given to Mathematica to plot using the
Table[ ]
In such case, Evaluate command forces evaluation of the command.
In[10]:=Plot[Evaluate[Table[ Cos[a*x],{a, 1, 5}]], (x, 0, 2Pi}];
34. ListPlot
ListPlot[ ] command draws a list of points, given as coordinate pairs (x, y).
ln[11]:= p3 =ListPlot[{{-5, -3}, {-3, 2}, {0.5, 6.3), {2.5, 1.4}, {5, 3}}, PlotJoined -> True];
To draw a plot joining the points (1, y1), (2,y2),..., (n , yn).
In[12]:= ListPlot[ { 2.5, 3.7, -1.2, 7.0, 9.1, -2.3}, PlotJoined->True ]
35. ContourPlot ContourPlot creates contours of an expression involving two variables. The contours are the curves on which the expression is constant. The contours are drawn on a rectangle. Ranges for each variable in the expression can be given.
In[12]:= p4 = ContourPlot[x^3 +y^2, {x, -3, 3}, {y, -3. 3}]
36. DensityPlot
This has the syntax similar to that of the ContourPlot[ ], but it has different options. For an expression involving two variables,this produces a shading of chosen rectangle.
In[13]:= DensityPlot[x^3 +y^2, {x, -3, 3}, {y, -3. 3}]
Plotting a Vector field <<VectorFieldPlots`;VectorFieldPlot[{x, y}, {x, 0, 1}, {y, 0, 1}]
Out[64]=
VectorPlot
(* Needs["Graphics`PlotField`"]; *)
<<VectorFieldPlots`;
vector={x, y}/(x^2 + y^2)^(3/2)
PlotVectorField[ vector, {x, -7,7,2}, {y, -7,7,2}] Out[35]=
Out[34]= xx2 y2 32 , yx2 y2 32
Gradient of Scalar
<<VectorFieldPlots`;
scalar=1/Sqrt[x^2+y^2]
PlotGradientField[scalar, {x,-5,5,2},{y,-5,5,2}]
Out[61]=1
x2 y2
Out[62]=
37. ParametricPlot
ParametriePlot[ ] draws the curve formed by a pair of expression
{x[t] , y[t]} as the parameter t varies.
In[14]:= ParametricPlot[ {Exp[-t/20] Cos[t],Exp[-t/20] Sin[t]} ,{t,0,50}]
38. ParametricPlot3DThis plots a parametrically defined three-dimensional curve (or a parametrically defined three-dimensional surface). It is part of the collection of Graphics packages, which must be loaded explicitly before it can be used,
In[15]:= <<Graphics`ParametricPlot3D`In[16]:= ParametricPlot3D[{Cos[x], Sin[x],x/4}, {x, 0, 2Pi}];
SphericalPlot
SphericalPlot3D[1+2 Cos[2 q], {q,0,Pi}, {f,0,2 Pi}]
Out[1]=
39. Plotting Spherical Harmonics (Math2.2)
Needs["Graphics`ParametricPlot3D`"] SphericalPlot3D[ Abs[ SphericalHarmonicY[3, 1, theta, phi] ], {theta, 0, Pi, Pi/30}, {phi, 0, 2 Pi, Pi/15}]
In Math 6.0
SphericalPlot3D[Abs[SphericalHarmonicY[3,1,theta,phi]],{theta,0,Pi},{phi,0,2 Pi}]
Out[1]=
SphericalPlot3D[Abs[SphericalHarmonicY[5,1,theta,phi]],{theta,0,Pi},{phi,0,2 Pi}]
Out[2]=
In[54]:= KnotData 5, 2
Out[54]=
In[58]:= KnotData 7, 3
Out[58]=
End of part III