MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002...

32
MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional plots. List plots Contour plots Density plots Parametric plots Parametric 3D-plots Anmation

Transcript of MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002...

Page 1: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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

Page 2: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

30. Two-Dimensional Plot

In[1]:= Plot[2x^3 –x^2 + 2, {x, -2, 2}]

Page 3: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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}]

Page 4: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

In[3]:= p2 = Plot[ Exp[-0.1 x] Sin[x],{x,-5,5},PlotRange->{-2,2}]

Page 5: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

In[4]:= Plot[Sin[x], {x, -Pi, Pi}, AxesLabel->{"x","Sin[x]"}]

Page 6: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

ln[5]:= Plot[Sin[t], {t, 0, 2Pi}, AxesLabel -> {"Time","Amplitude"}, PlotLabel —> "Sine Wave"]

Page 7: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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

Page 8: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

Mathematica also has ability to cope with poles.

In[6]:= Plot[ 1/Sin[x], {x, -Pi, Pi}]

Page 9: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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].

Page 10: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

31.1 ShowThe Show[ ] command superimposes many plots. For instance, plotting some of the earlier named plots, type

In[8]:= Show[p1, p2]

Page 11: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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]=

Page 12: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

In[44]:= ShowGraphics GrayLevel.5,Thickness0.04,

Line 0, 0, 1, 1, 2, 0, 0, 0

Out[44]=

Page 13: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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

Page 14: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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}]

Page 15: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

In[9]:= Plot3D[Sin[x] Cos[y] , {x.-Pi.Pi}, {y.-2Pi.2Pi}, AxesLabel -> {x,y,z}, PlotPoints->40]

Page 16: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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}];

Page 17: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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];

Page 18: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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 ]

Page 19: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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}]

Page 20: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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}]

Page 21: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

Plotting a Vector field <<VectorFieldPlots`;VectorFieldPlot[{x, y}, {x, 0, 1}, {y, 0, 1}]

Out[64]=

Page 22: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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

Page 23: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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]=

Page 24: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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}]

Page 25: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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}];

Page 26: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

SphericalPlot

SphericalPlot3D[1+2 Cos[2 q], {q,0,Pi}, {f,0,2 Pi}]

Out[1]=

Page 27: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

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}]

Page 28: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

In Math 6.0

SphericalPlot3D[Abs[SphericalHarmonicY[3,1,theta,phi]],{theta,0,Pi},{phi,0,2 Pi}]

Out[1]=

Page 29: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

SphericalPlot3D[Abs[SphericalHarmonicY[5,1,theta,phi]],{theta,0,Pi},{phi,0,2 Pi}]

Out[2]=

Page 30: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

In[54]:= KnotData 5, 2

Out[54]=

Page 31: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

In[58]:= KnotData 7, 3

Out[58]=

Page 32: MATHEMATICA – AN INTRODUCTION R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART III- GRAPHICS Two-dimensional plots Three-dimensional.

End of part III