1 / 24

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

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

corbin
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 Fourier Transform FullForm of Mathematica commands

  2. 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] = 2 1.8088 + 0.142048 x + 0.0676953 x

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

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

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

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

  7. 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 Ylm(theta, phi) Cyclotomic[n, z] gives Cyclotomic Cyn(z)

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

  9. Examples: on Hermite functions In[163]:= h = HermiteH[8,x] Out[163] = 2 4 6 8 1680 - 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 6 2822400 - 45158400 x + 225792000 x - 373309440 x + 8 10 12 277831680 x - 103219200 x + 19726336 x - 14 16 1835008 x + 65536 x

  10. 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 p 8 n + 96 p 384 p In[167]:= Solve[ {f1==1, f2==10, f3== 100}, {m,n,p}] Out[167] = 239 15 25 {{m -> ----, n -> -(--), p -> --}} 24 8 96

  11. 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// ExpandAll Out[169] = 2 2 (-1 + 3 z ) t 1 + z t + -------------- + 2 2 5 z (-1 + 3 z ) 3 (-2 z + ---------------) t 2 --------------------------- + 3 4 + O[t]

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

  13. In[172]:= Do[ Print["Cy",n," = ", Cyclotomic[n,z]], {n,6} ] Print["Cy", 50, " = ", Cyclotomic[50,z]] Out[172] = Cy1 = -1 + z Cy2 = 1 + z 2 Cy3 = 1 + z + z 2 Cy4 = 1 + z 2 3 4 Cy5 = 1 + z + z + z + z 2 Cy6 = 1 - z + z 5 10 15 20 Cy50 = 1 - z + z - z + z

  14. 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}

  15. Integral Transforms

  16. 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}

  17. 77. FullForm of Mathematica commands In[179]:= a+2 I b //FullForm Out[179] = Plus[a, Times[Complex[0, 2], b]] In[180]:= FullForm[a + 2*I*b] Out[180] = Plus[a, Times[Complex[0, 2], b]]

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

  19. End of part VII

More Related