Python for Education - IUAC

Huge amount of material is already available online on the topics covered, and the references to .... 2.21 Object Oriented Programming in Python . ..... However, to write your own computer programs, you need to learn some ...... The method upper() (a function belonging to a class is called a method) is invoked using the dot.
4MB Sizes 102 Downloads 257 Views
Python for Education

Learning Maths & Science using Python and writing them in LATEX

Ajith Kumar B.P. Inter University Accelerator Centre New Delhi 110067 www.iuac.res.in

June 2010

2

Preface Mathematics, rightly viewed, possesses not only truth, but supreme beauty  a beauty cold and austere, like that of sculpture, without appeal to any part of our weaker nature, without the gorgeous trappings of painting or music, yet sublimely pure, and capable of a stern perfection such as only the greatest art can show, wrote Bertrand Russell about the beauty of mathematics. All of us may not reach such higher planes, probably reserved for Russels and Ramanujans, but we also have beautiful curves and nice geometrical gures with intricate symmetries, like fractals, generated by seemingly dull equations. This book attempts to explore it using a simple tool, the Python programming language. I started using Python for the Phoenix project (www.iuac.res.in). Phoenix was driven in to Python by Pramode CE (pramode.net) and I followed. Writing this document was triggered by some of my friends who are teaching mathematics at Calicut University. In the rst chapter, a general introduction about computers and high level programming languages is given. Basics of Python language, Python modules for array and matrix manipulation, 2D and 3D data visualization, type-setting mathematical equations using latex and numerical methods in Python are covered in the subsequent chapters. Example programs are given for every topic discussed. This document is meant for those who want to try out these examples and modify them for better understanding. Huge amount of material is already available online on the topics covered, and the references to many resources on the Internet are given for the benet of the serious reader. This book comes with a live CD, containing a modied version of Ubuntu GNU/Linux operating system. You can boot any PC from this CD and practice Python. Click on the 'Learn by Coding' icon on the desktop to browse through a collection of Python programs, run any of them with a single click.

You can practice Python very easily by modifying and running these example

programs.

AT X front-end. It is distributed under the GNU Free This document is prepared using LYX, a L E Documentation License (www.gnu.org). Feel free to make verbatim copies of this document and distribute through any media. For the LYX source les please contact the author. Ajith Kumar IUAC , New Delhi ajith at iuac.res.in

Contents 1 Introduction

6

1.1

Hardware Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2

Software components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

1.2.1

The Operating System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

1.2.2

The User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

1.2.2.1

. . . . . . . . . . . . . . . . . . . . . . .

7

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

9

1.2.3

The Command Terminal

The File-system 1.2.3.1

Ownership & permissions . . . . . . . . . . . . . . . . . . . . . . .

1.2.3.2

Current Directory

6

9

. . . . . . . . . . . . . . . . . . . . . . . . . . .

10

1.3

Text Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

1.4

High Level Languages

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

1.5

On Free Software . . . . . . . . . . . . . . . . . . . . . . . . . . .