MATHEMATICA - Department of Physics

Download Report

Transcript MATHEMATICA - Department of Physics

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)
•
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/
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
MATHEMATICA – AN INTRODUCTION
Part I: Basics and Arithmetics
Input and Output
Number Representation & Arithmetic Computations
Built-in Constants & Functions
Complex Arithmetic Operations
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
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.
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/
2. What can Mathematica do for you?
STANDARD ARITHMETIC
Operations with Integer, Rational, Real, and Complex nos with LARGE precision
RICH in Built-in Constants & functions; Special functions, Creating New functions
ALGEBRA
Factorization, Simplification, Reduction, Solution of Simultaneous equations
List manipulation: Vector, Matrix & Tensor operations; Sums & Products
GRAPHICS
2D, 3D, Contour, Density, Parametric plots, Listplot; Sound and Animation
CALCULUS
Limits, 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,
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
WebMathematica
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.
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
or
type double question marks ?? before the command name.
For instance
??Integrate
Math 6.0 - Help
• Documentation Center
• Index of Functions
• 5 minutes with Mathematica
• Demonstration Projects
Special Features (given in Help)
•
Core Language
The uniquely powerful symbolic language that is the foundation for
Mathematica
Mathematics and Algorithms
The world's largest integrated web of mathematical capabilities and
algorithms
Data Handling & Data Sources
Powerful primitives and sources for large volumes of data in hundreds
of formats
Visualization and Graphics
Symbolic graphics and unparalleled function and data visualization
Systems Interfaces & Deployment
Unique customizability and connectivity powered by symbolic
programming & parallel programming
Dynamic Interactivity
Capabilities that define a new kind of dynamic interactive computing
Notebooks and Documents
Program-constructible symbolic documents with uniquely flexible
formatting.
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
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.
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^37
Out[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^37
Out[3] =
31
1.85621 10
9. Variable Assignments
A single equal sign is used to assign values directly to a variable.
In[4]:= weight= 0.542
Out[4]= 0.542
In[5]:= counter = 1
Out[5]= 1
Arithmetic expression may also be assigned to a variable,
In[6]:= y = x*x
Out[6] =
2
x
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!
11. Numerical Resolution
Mathematica can produce its approximate form, when N[ expression ] command is
used.
In[9]:= N[ 3^85 ]
Out[9]=
40
3.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
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
i 
1
and Infinity.

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
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 number
In[29]:= FactorInteger[20645081]
Out[29] = {{1753, 1}, {11777, 1}}
Chopping a result
Chop[ expression ]
Replaces all approximate real numbers with magnitude less than 10
-10
by zero.
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
15. Trigonometric Functions
Sin[x]
sine of x
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
x must be in radians.
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
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
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
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
17. Complex Arithmetic Operations
Complex numbers can be entered in the form x + y * l,
ln[41]:= z = 3.5 + 6.8 I
Out[41]= 3.5 + 6.8 I
Re[z] yields real part, x, of complex number z = x + i y
ln[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 y
ln[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
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)^8
Out[47] = 13.4344 - 23.9958 I
End of Part I