mathematica – an introduction: r.c. verma physics department punjabi university patiala – 147...
DESCRIPTION
MATHEMATICA – AN INTRODUCTION: R.C. Verma Physics Department Punjabi University Patiala – 147 002 PART VII- ADDITIONAL FEATURES Curve fitting Trigonometric and Exponential Expressions Testing functions Special Functions Orthogonal Polynomials Combinatorics: Permutations - PowerPoint PPT PresentationTRANSCRIPT
MATHEMATICA – AN INTRODUCTION:
R.C. VermaPhysics DepartmentPunjabi UniversityPatiala – 147 002
PART VII- ADDITIONAL FEATURES
Curve fitting
Trigonometric and Exponential Expressions
Testing functions
Special Functions
Orthogonal Polynomials
Combinatorics: Permutations
Fourier Transform
FullForm of Mathematica commands
70. Curve fitting:
For a numerical data, it is often desired to find a simple polynomial function that approximates it.
Fit[ data, {1, x}, x] gives the best linear fit
Fit[ data, {1, x, x^2}, x] gives the best quadratic fit
In[123]:= numdata = Table[ Exp[x/4.0], {x, 5}]Out[123] = {1.28403, 1.64872, 2.117, 2.71828,
3.49034}
In[124]:= Fit[numdata, {1, x, x^2}, x]Out[124] =
21.8088 + 0.142048 x + 0.0676953 x
Examples:
In[125]:= table = Table[ n!, {n,1,15}]Out[125] = {1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000 }
In[126]:= logtable = N[ Log[table]]Out[126] = {0, 0.693147, 1.79176, 3.17805, 4.78749, 6.57925, 8.52516, 10.6046, 12.8018, 15.1044, 17.5023, 19.9872, 22.5522, 25.1912, 27.8993}
In[127]:= Fit[logtable, {1,x,x^2,x^3}, x]Out[127] = 2 3
-0.700245 + 0.454654 x + 0.144605 x - 0.00320604 x
71. Dealing with Trigonometric and Exponential Expressions:
Mathematica has built-in functions for transforming Trigonometric and Exponential expressions.
TrigExpand[ expression]
expands out trigonometric expression into sum of trigonometric terms.
TrigToExp[ expression]
coverts trigonometric expression to exponential form.
ExpToTrig[ expression]
coverts exponential expression to trigonometric form.
72. Testing functions(Result: True/False)
IntegerQ[n] tests whether n is an integer,
OddQ[n] tests whether n is odd,
EvenQ[n] tests whether n is even,
PrimeQ[n] tests whether n is a prime,
In[156]:= OddQ[3]Out[156]= True
73. Special Functions
Beta[a, b] gives Euler beta function B(a, b)
Gamma[ x] gives Euler gamma function, gamma(x).
Zeta[s] gives Riemann zeta function zeta(s)
Erf[z] gives error function erf(z)
Example:
In[157]:= N[ Zeta[ 1/3 + 15 I], 20]Out[157] = 0.008303807201447016 + 0.789018414658470727 I
In[3] := Plot Gammax, x, 0.1, 5
Out[3]=
1 2 3 4 50
5
10
15
20
In[30]:= epsilon 10^ 16;
PlotAbsGamma1 I y ^2 Pi y SinhPi y, y, 2, 3,PlotRange epsilon, epsilon
Out[31]=2 .2 2 .4 2 .6 2 .8 3 .0
1 . 10 16
5 . 10 17
5 . 10 17
1 . 10 16
In[4] := Plot Abs Zeta 1 2 I y, y, 0, 40
Out[4]=
10 20 30 40
0 .5
1 .0
1 .5
2 .0
2 .5
3 .0
74. Orthogonal Polynomials
BesselJ[n, x] gives Bessel function of first kind Jn(x).
BesselY[n, x] gives Bessel function of second kind Yn(x).
HermiteH[n, x] gives Hermite Polynomial Hn(x)
LaguerreL[n, x] gives Laguerrel Polynomial Ln(x)
LegendreP[n, x] gives Legendre Polynomial Pn(x)
LegendreP[n, m, x] gives associated Legendre Polynomial Pmn(x)
SphericalHarmonicY[l, m, theta, phi] gives spherical Harmonics Yl
m(theta, phi)
Cyclotomic[n, z] gives Cyclotomic Cyn(z)
In[5] := Plot BesselJ0, x, x, 0, 30
Out[5]=
5 10 15 20 25 30
0 .4
0 .2
0 .2
0 .4
0 .6
0 .8
1 .0
Examples: on Bessel functions
In[158]:= BesselJ[0,15.2]Out[158] = -0.0544208
In[159]:= FindRoot[ BesselJ[1,x], {x, 8.0}]Out[159] = {x -> 7.01559}
In[160]:= FindRoot[ BesselY[2, x], {x, 20.0}]Out[160] = {x -> 18.0642}
In[161]:= f[n_, x_]:= BesselJ[n, x] f[0, 1.75]
Out[161] = 0.369033
In[162]:= BesselJ[0,1.75]Out[162] = 0.369033
Examples: on Hermite functions
In[163]:= h = HermiteH[8,x]Out[163] =
2 4 6 81680 - 13440 x + 13440 x - 3584 x + 256 x
In[164]:= Print[ D[h,x]]Out[164] = 3 5 7
-26880 x + 53760 x - 21504 x + 2048 x
In[165]:= Expand[h^2]Out[165] = 2 4 62822400 - 45158400 x + 225792000 x - 373309440 x + 8 10 12 277831680 x - 103219200 x + 19726336 x - 14 16 1835008 x + 65536 x
In[166]:= f[x_]:= m HermiteH[0,x] + n HermiteH[2,x] + p HermiteH[4,x]
f1=f[1]f2=f''[1]f3=f''''[1]
Out[166]= m + 2 n - 20 p8 n + 96 p384 p
In[167]:= Solve[ {f1==1, f2==10, f3== 100}, {m,n,p}]Out[167] = 239 15 25
{{m -> ----, n -> -(--), p -> --}} 24 8 96
In[168]:= legen=Series[(1- 2 z t + t^2)^(-1/2), {t,0,4}] 2
z (-3 + 5 z )Out[168] =-------------
2
In[169]:=Coefficient[Normal[legen], t,2]//Simplify// ExpandAllOut[169] = 2 2 (-1 + 3 z ) t1 + z t + -------------- + 2 2 5 z (-1 + 3 z ) 3 (-2 z + ---------------) t 2 --------------------------- + 3
4+ O[t]
In[170]:= LegendreP[3,z]Out[170] = 3
-3 z 5 z---- + ----
2 2
In[171]:= leg[n_, z_]:= D[(z^2-1)^n, {z, n}]/(2^n n!) Print[Simplify[leg[3,z]]]
Out[171] = 3
-3 z + 5 z-----------
2
In[10]:= Plot LegendreP3, Cosy, y, 0, 2Pi
Out[10]=1 2 3 4 5 6
1 .0
0 .5
0 .5
1 .0
In[172]:= Do[ Print["Cy",n," = ", Cyclotomic[n,z]], {n,6} ] Print["Cy", 50, " = ", Cyclotomic[50,z]]
Out[172] =Cy1 = -1 + zCy2 = 1 + z 2Cy3 = 1 + z + z 2Cy4 = 1 + z 2 3 4Cy5 = 1 + z + z + z + z 2Cy6 = 1 - z + z 5 10 15 20Cy50 = 1 - z + z - z + z
75. Combinatorics:
Permutations
In[173]:= Permutations[{a,b,c}]Out[173] = {{a, b, c},{a, c, b},{b, a, c},{b, c, a}, {c, a, b}, {c, b, a}}
In[174]:= Flatten[%]Out[174]= {a, b, c, a, c, b, b, a, c, b, c, a, c, a, b, c, b, a}
Integral Transforms
FourierTransform Expt^2 Sint, t, 1 Cosh Sinh Cosh 1
41 2 Sinh 1
41 2
2 2
FourierTransform1, t, 2 DiracDelta
LaplaceTransformt^4Sint, t, s24 1 10 s2 5 s41 s2 5InverseLaplaceTransform1 1 s, s, t t
76. Fourier Transform
In[175]:= <<Calculus`FourierTransform` FourierTransform[t^2 Sin[t], t,w]
Out[175] = -I Pi DiracDelta''[1 - w] + I Pi DiracDelta''[1 + w]
In[176]:= data = {1,1,1,1, -1, -1,-1,-1};
In[177]:= N[Fourier[data]]Out[177]={0.+ 0. I, 1.20711 + 0.5 I, 0. + 0. I, 0.207107+ 0.5 I, 0. + 0. I, 0.207107 - 0.5 I, 0. + 0. I, 1.20711 - 0.5 I}
77. FullForm of Mathematica commands
In[179]:= a+2 I b //FullFormOut[179] = Plus[a, Times[Complex[0, 2], b]]
In[180]:= FullForm[a + 2*I*b]Out[180] = Plus[a, Times[Complex[0, 2], b]]
ArrayPlotCellular automata provide a convenient way to represent many kinds of systems in which the values of cells in an array are updated in discrete
steps according to a local rule.
In[12]:= ArrayPlotCellularAutomaton50, RandomInteger1, 250, 100Out[12]=
End of part VII