Top Banner
Art of Symbolic Computing - I using MATHEMATICA (A Fully Integrated Environment for Technical Computing) Software and Applications R.C. Verma Physics Department Punjabi University Patiala – 147 002 Refresher Course in Physics Panjab University Sept. 2010
43

Refresher Course in Physics Panjab University Sept. 2010

Feb 11, 2016

Download

Documents

brody

Art of Symbolic Computing - I using MATHEMATICA (A Fully Integrated Environment for Technical Computing) Software and Applications R.C. Verma Physics Department Punjabi University Patiala – 147 002. Refresher Course in Physics Panjab University Sept. 2010. Education (Some Indian Statistics). - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Refresher Course in Physics Panjab University Sept. 2010

Art of Symbolic Computing - Iusing MATHEMATICA

(A Fully Integrated Environment for Technical Computing)Software and Applications

R.C. VermaPhysics DepartmentPunjabi UniversityPatiala – 147 002

Refresher Course in PhysicsPanjab University

Sept. 2010

Page 2: Refresher Course in Physics Panjab University Sept. 2010

Education (Some Indian Statistics)• Total population below 14 is around 250 million.

• Maximum number of ‘out of school’ children in world.• Nowhere Children:- Around 90 million children are neither enrolled in

school nor accounted for as labour.

• Only 60% of children reach grade V.• Many of those ‘completing’ primary school cannot read or write.• Every child is curious, creative, intelligent, innocent and beautiful. • Why and where he loose these qualities.

• Somewhere society (present normal setup of mind, current values and education modes) is responsible for this state of affairs.

• Hope:- Efforts under UGC, DST, NMEICT of MHRD etc.

• http://www.sakshat.ac.in/

Page 3: Refresher Course in Physics Panjab University Sept. 2010

NMEICT (MHRD) www.sakshat.ac.in

• Around 30 programs:-

1. e-content development in all the branches of knowledge at UG and PG levels,

2. Development of Pedagogical methods of teaching and research in e-learning,

3. Teachers empowerment through training in Computer Applications to various subjects in Universities and Colleges,

4. Development of Computer Simulation packages in various subjects of science and humanities,

5. Introduction of one compulsory paper/project for on-line training at PG level

• More details on these and other activities of the mission can be obtained from the following file web-link:

• http://www.sakshat.ac.in/PDF/Missiondocument.pdf

Page 4: Refresher Course in Physics Panjab University Sept. 2010

MATHEMATICA – AN INTRODUCTION

Part I: Basics and Arithmetics

Input and Output

Number Representation & Arithmetic Computations

Built-in Constants & Functions

Complex Arithmetic Operations

Page 5: Refresher Course in Physics Panjab University Sept. 2010

Introduction:-Computer-based symbolic computation has a very significant role in

computer world. Still it is a very under-used, probably because of a reluctance to break from tradition. Today symbolic manipulation has become a powerful tool, which boosts productivity

It runs on most popular workstation OS, including Microsoft Windows, Apple Macintosh OS, Linux, and other Unix-based systems.

Mathematica today is used in all the branches of knowledge:

• Physical science,• Biological science, • Social science, • Commerce, • Education, • Enginering,• Computer science, etc.

Over 100 specialized commercial packages and

over 200 books for Mathematica and its applications

Page 6: Refresher Course in Physics Panjab University Sept. 2010

0. Phases of the computer algebra:-

First Generation:

Reduce has packages suited to the needs of the high energy physicist. Macsyma is slow and lacks a friendly interface.

Second Generation:

Maple has strong algebraic and graphics capability.

Third Generation:

Mathematica is a very user-friendly interface and superb graphic abilities. A standard tool for research, development and production of software.MatLab & MathCad are also available with similar facilities.

Page 7: Refresher Course in Physics Panjab University Sept. 2010

1. Who Created Mathematica?

Stephen Wolfram is the creator of Mathematica.

His early work: mainly in high-energy physics, quantum field theory, and cosmology.

In 1979, he began the construction the computer algebra system.

He began the development of Mathematica in 1986.

1st version released on June 23, 1988, hailed as a major advance in computing world.

In 1991, its Window version 2 was developed by him and his team.

Before 2004, versions 3, 4 and 5, now 6 introduced with new capabilities.

Parallel Processing and Grid-Mathematica have also been launched.

http://www.wolfram.com/

Page 8: Refresher Course in Physics Panjab University Sept. 2010

2. What can Mathematica do for you?

STANDARD ARITHMETICOperations with Integer, Rational, Real, and Complex nos with LARGE precisionRICH in Built-in Constants & functions; Special functions, Creating New functions

ALGEBRAFactorization, Simplification, Reduction, Solution of Simultaneous equationsList manipulation: Vector, Matrix & Tensor operations; Sums & Products

GRAPHICS 2D, 3D, Contour, Density, Parametric plots, Listplot; Sound and Animation

CALCULUSLimits, Differentiation and integration, Taylor Series, Solving Differential Eqns.

NUMERICAL ANALYSIS: Root Finding, Numerical Integration, Solving Differential Eqns., Curve Fitting, etc.

PROGRAMMING In-built Interpreted Programming Language, also with Compilation facility

FORMATTED OUTPUT: TeX, C and Fortran output,

Page 9: Refresher Course in Physics Panjab University Sept. 2010

3. Structure of Mathematica

Modular software system:-

KERNEL: main engine of the system containing all the functions (over 1000)

WMATHEXE.EXP 3,979,305 (for Window Math2.2 version)

FRONT-END: serves as the channel on which a user communicates with the kernel.

STANDARD PACKAGES: special topics, like vector analysis, statistics, algebra, to graphics, etc.

MATHSOURCE: collection of packages and notebooks created by Mathematica users.Feyndia, Math-Tensor, Graphics, and other Addons

Page 10: Refresher Course in Physics Panjab University Sept. 2010
Page 11: Refresher Course in Physics Panjab University Sept. 2010
Page 12: Refresher Course in Physics Panjab University Sept. 2010

WebMathematica

Page 13: Refresher Course in Physics Panjab University Sept. 2010

4. Ten Commandments

1. Mathematica distinguishes between uppercase and lowercase letters.

2. Mathematica commands, built-in functions, & constants start with a capital letter. 3. Use lowercase letters for defining variables or functions.

4. Arguments of all commands & functions are enclosed in square brackets [ ]. 5. Use curly brackets { } for lists of items, and range of parameters of the function. 6. Parenthesis ( ) is reserved for indicating the grouping of terms.

7. Double brackets [ [ ] ] are used for indexing the components of an object.

8. All functions, for numerical calculations, start with a capital N.

9. Giving Remarks. Statements starting with (* and ends with *) are not executed.

10. When Mathematica detects a syntax error, it prints a message.

Page 14: Refresher Course in Physics Panjab University Sept. 2010

5. How to Start Mathematica and Execute its Commands?

Double click the Mathematica icon, or Math.Exe file

When Mathematica starts, it shows you a blank notebook.

Enter Mathematica commands into the notebook, and then press Shift-Enter keys to process the input given.

Pressing the Enter key generates a new line.

For getting Help on Mathematica Commands, use Help ortype double question marks ?? before the command name.

For instance ??Integrate

Page 15: Refresher Course in Physics Panjab University Sept. 2010
Page 16: Refresher Course in Physics Panjab University Sept. 2010
Page 17: Refresher Course in Physics Panjab University Sept. 2010

Math 6.0 - Help

• Documentation Center

• Index of Functions

• 5 minutes with Mathematica

• Demonstration Projects

Page 18: Refresher Course in Physics Panjab University Sept. 2010

Special Features (given in Help)• Core Language

The uniquely powerful symbolic language that is the foundation for Mathematica

Mathematics and AlgorithmsThe world's largest integrated web of mathematical capabilities and algorithms

Data Handling & Data SourcesPowerful primitives and sources for large volumes of data in hundreds of formats

Visualization and GraphicsSymbolic graphics and unparalleled function and data visualization

Systems Interfaces & DeploymentUnique customizability and connectivity powered by symbolic

programming & parallel programmingDynamic Interactivity

Capabilities that define a new kind of dynamic interactive computingNotebooks and Documents

Program-constructible symbolic documents with uniquely flexible formatting.

Page 19: Refresher Course in Physics Panjab University Sept. 2010
Page 20: Refresher Course in Physics Panjab University Sept. 2010
Page 21: Refresher Course in Physics Panjab University Sept. 2010
Page 22: Refresher Course in Physics Panjab University Sept. 2010
Page 23: Refresher Course in Physics Panjab University Sept. 2010
Page 24: Refresher Course in Physics Panjab University Sept. 2010
Page 25: Refresher Course in Physics Panjab University Sept. 2010
Page 26: Refresher Course in Physics Panjab University Sept. 2010

6. Input and Output Labels

In[1] : =

An input label appears at the beginning of every Input cell.

These are numbered according to the order of evaluation.

The result of the command is displayed in an Output cell,

Out[n]=

which is labeled according to the input label.

Mathematica formats the material in Output cells in mathematical notation. e.g.

type 5.3+2.9 and press Shift-Enter keys

Mathematica shows:

In[1]:= 5.3 + 2.9 Out[1] = 8.2

Page 27: Refresher Course in Physics Panjab University Sept. 2010

7. Number Representation & Arithmetic Computations

Mathematica can distinguish between

integer, rational, real, complex numbers.

Following symbols are used to denote them:

Addition +

Subtraction -

Multiplication *

Division /

Exponentiation ^

Parenthesis ( ) can be used to change order of operations.

Note: - Multiplication can be represented by a space.

Caution: x y means x * y but xy is treated as a new variable xy.

Page 28: Refresher Course in Physics Panjab University Sept. 2010

8. MIXED MODE OPERATIONS:

When two constants or variables of the same type are combined through any of these fundamental operations, the result would be of the same type as that of the operands.

Mathematica gives out of integer operation as integer,

In[2] := 7^37Out[2] = 18562115921017574302453163671207

Mathematica allows the mixed mode operations, e.g, where real number and integer are used. Result in such a case is given as real number.

In[3] := 7.0^37Out[3] =

311.85621 10

Page 29: Refresher Course in Physics Panjab University Sept. 2010

9. Variable Assignments

A single equal sign is used to assign values directly to a variable.

In[4]:= weight= 0.542Out[4]= 0.542

In[5]:= counter = 1Out[5]= 1

Arithmetic expression may also be assigned to a variable,

In[6]:= y = x*xOut[6] =

2 x

Page 30: Refresher Course in Physics Panjab University Sept. 2010

10. Writing Results:

Results obtained in a program are generally written using the following statement:

Print[ variable ]

Messages can be printed on screen by enclosing them in double quote (“) sign:

In[8]:= Print[“You are welcome!”]Out[8] = You are welcome!

Page 31: Refresher Course in Physics Panjab University Sept. 2010

11. Numerical Resolution

Mathematica can produce its approximate form, when N[ expression ] command is used.

In[9]:= N[ 3^85 ] Out[9]=

403.59175 10

Here, N stands for numerical, and the command can be given as expression // N. e.g.

In[9]:= 3^85//N

To get the result up to a desired number of decimal place, say n digit precision,

type N[ expression, n ]

In[10]:= N[3^85, 10] Out[10]=

40 3.591754555 10

Page 32: Refresher Course in Physics Panjab University Sept. 2010

12. Built-in Constants

Pi (ratio of circumference to diameter, Pi = 3.141592…),

In[11]:= N[ Pi, 100]Out[11]=3.141592653589793238462643383279502884197169399375\

105820974944592307816406286208998628034825342117068

E (the base e of the natural logarithm, e = 2.71828….),

In[12]:= N[ E ]Out[12]= 2.71828

Degree (Pi/180: degree to radian conversion factor)

In[13]:= Sin[60 Degree ]Out[13]= Sin[60 Degree]

In[14]:= N[Sin[60 Degree]]Out[14]= 0.866025

Mathematica is also familiar with iota I and Infinity.

1i

Page 33: Refresher Course in Physics Panjab University Sept. 2010

Built-in Functions in Mathematica

13. Numerical Functions

Abs[x] gives the absolute value of x. In[21]:= Abs[ -5 ]Out[21]= 5

Sqrt[x] returns the square root (with positive sign) In[22]:= N[ Sqrt[15], 50]Out[22] =

3.8729833462074168851792653997823996108329217052916

Round[x] produces the closest integer to x.In[26]:= Round[3.67]Out[26]= 4

Sign [x] yields sign as –1, 0, 1 for x > 0, x = 0, x < 0 respectively.In[27]:= Sign[-4]Out[27]= -1

Page 34: Refresher Course in Physics Panjab University Sept. 2010

Factorial: n! yields the factorial of integer n. In[23]:= 6!Out[23]= 720

In[24]:= Factorial[6]Out[24]= 720

n!! yields double factorial n(n-2)(n-4)…..In[25]:= 10!!Out[25]= 3840

Prime[k] gives kth prime number.In[28]:= Prime[5]Out[28]= 11

FactorInteger[ number] gives prime factors of the given numberIn[29]:= FactorInteger[20645081]Out[29] = {{1753, 1}, {11777, 1}}

Chopping a resultChop[ expression ]

Replaces all approximate real numbers with magnitude less than 10-10 by zero.

Page 35: Refresher Course in Physics Panjab University Sept. 2010

14. Logarithmic and Exponential Functions

Log[x] gives logarithm of x to base e.

In[30]:= N[ Log [4 Pi], 40]Out[30]= 2.5310242469692907929778915942694118477983

Log[b, x] yields logarithm of x to base b.

In[31]:= Log[3, 50.0]Out[31]= 3.56088

Exp[x] gives exponential of x.

In[32]:= Exp[-2.5]Out[33]= 0.082085

Page 36: Refresher Course in Physics Panjab University Sept. 2010

15. Trigonometric Functions Sin[x] sine of x x must be in radians.

Cos[x] cosine of x -do-

Tan[x] tangent of x -do-

Cot[x] cotangent of x -do –

Sec[x] secant of x -do –

Csc[x] cosecant of x -do –

In[33]:= Cos[Pi/4]Out[33]=

1-------Sqrt[2]

In[34]:= Tan[3Pi/4]Out[34]= -1

Page 37: Refresher Course in Physics Panjab University Sept. 2010

15.1 Inverse Trigonometric Functions

ArcSin[x] inverse of sine ArcCos[x] inverse of cosine

ArcTan[x] inverse of tangent

ArcCot[x] inverse of cotangent ArcSec[x] inverse of secant ArcCsc[x] inverse of cosecant

In[35]:= ArcTan[-1]Out[35]=

-Pi---

4

Page 38: Refresher Course in Physics Panjab University Sept. 2010

15.25 Hyperbolic Functions

Sinh[x] hyperbolic-sine of x

Cosh[x] hyperbolic-cosine of x Tanh[x] hyperbolic- tangent of x Coth[x] hyperbolic-cotangent of x Sech[x] hyperbolic-secant of x Csch[x] hyperbolic-cosectant of x

In[36]:= Sinh[2.0]Out[36]= 3.62686

Page 39: Refresher Course in Physics Panjab University Sept. 2010

15.3 Inverse Hyperbolic Functions

ArcSinh[x] inverse-hyperbolic-sine of x

ArcCosh[x] inverse-hyperbolic-cosine of x ArcTanh[x] inverse-hyperbolic- tangent of x ArcCoth[x] inverse-hyperbolic-cotangent of x ArcSech[x] inverse-hyperbolic-secant of x ArcCsch[x] inverse-hyperbolic-cosectant of x

In[37]:= ArcCosh[2.0]Out[37]= 1.31696

Page 40: Refresher Course in Physics Panjab University Sept. 2010

16. Functions involving two or more arguments

MOD[m, n] command yields the remainder on division of m by n.

In[38]:= Mod[237, 13]Out[38]= 3

Max[x1,x2, x3, ….] gives largest number

In[39]:= Max[ 2.3, 1.2, 6.7, 3.8, 0.1]Out[39]= 6.7

Min[x1,x2, x3, ….] gives smallest number

In[40]:= Min[2.3, 1.2, 6.7, 3.8, 0.1]Out[40]= 0.1

Page 41: Refresher Course in Physics Panjab University Sept. 2010

17. Complex Arithmetic Operations

Complex numbers can be entered in the form x + y * l, ln[41]:= z = 3.5 + 6.8 IOut[41]= 3.5 + 6.8 I

Re[z] yields real part, x, of complex number z = x + i yln[42]:= Re[z]Out[42]= 3.5

Im[z] yields imaginary part, y, of complex number z = x + i y.

Abs[z] yields absolute value, |z| = V(x^2 +y^2), of complex number z = x + i yln[43]:= Abs[z]Out[43]= 7.64788

Arg[z] yields argument, Tan-1(y/x) of a complex number z = x + i y, or for z = |z|ei

ln[44]:= Arg[z]Out[44]= 1.09545

Conjugate[z] produces complex conjugate, z* = x – i y, for z = x + i y.ln[45]:= Conjugate[z]Out[45]= 3.5 - 6.8 I

l

Page 42: Refresher Course in Physics Panjab University Sept. 2010

One can performs basic arithmetic operations,

addition, subtraction, multiplication,

division, exponentiation

on the complex numbers.

ln[46]:= (2+3I)(4-I)Out[46]= 11 + 10 I

In[47]:= (1.5 - 0.2 I)^8Out[47] = 13.4344 - 23.9958 I

Page 43: Refresher Course in Physics Panjab University Sept. 2010

End of Part I