Skip to main content

Overview of Scientific Computing


Introduction

Scientific computing broadly means computations carried out for scientific or engineering needs. This mostly includes processing of large arrays or matrices, plotting of functions, solving equations, performing mathematical transforms etc very fast while keeping programming hassles at a minimum.

Requirements of Scientific Computing

The language for scientific computing

  • should be Interpreted
  • should be modular
  • should have easy routines for array, matrix and vectors
  • should have a publication quality plotting library

Python for Scientific Computing

Python is an interpreted, modular language that is suitable for scientific computing. Modules such as numpy, scipy etc provide many scientific computing tools. The module matpplotlib alias pylab provides publication quality plotting libraries. Python 2.7 and Python 3 are available in all major Linux distros and can be installed as bundle such as anaconda in Windows. An enhanced Python shell ipython is very helpful and has more functionality than MATLAB and IDL command lines.

Installation of scipy, matplotlib and Ipython

The three modules are implemted in apt -based systems such as Ubuntu, Debian etc as
sudo apt-get install python-scipy python-matplotlib ipython ipython3
The modules are available in anaconda for Windows.

Working

  • Take a terminal in Linux and type ipython and the interactive Python shell launches
  • Everything in the modules are imported as
    • from scipy import *

    • from pylab import *

You may get help on these modules by typing
  • help(scipy)

  • help(pylab)

Data Types in Python

Python is an object oriented language and everything in Python is an object. The various data types are listed in Table 1.

Table 1: Data types in Python

No.
Data Type Description

1
Numbers The numbers can be integers, float, fractions or complex.
2 Boolean Can be True or False
3 String Sequence of unicode characters
4 List Sequence of ordered homogenous values
5 Tuples Sequence of heterogenous values
6 Bytes, Bytearray These are binary buffers that represent bytes (numbers 0 through 255), often helpful in image processing.
7 Sets Set is an unordered collection with no duplicate elements.

What You Learned

  • You understood the requirements of scientific computing

  • You understood the use of Python for scientific computing and its data types

  • You learned the use of scipy and pylab and the syntax for importing them.

Comments

Popular posts from this blog

Functions in Python

Functions in Python Dr. Hari V S Department of Electronics and Communication College of Engineering Chengannur What You will Learn You will learn the syntax of Python functions You will learn to import the functions to other codes The Syntax The syntax used the keyword $def$ followed the name of the function again followed by a colon (:) that is then followed by an indented code block of instructions. The function def function_name(arg1.arg2,....argN): statements return results A Simple Python Function Needless to say that the statements and the return command should form an indented block. Consider a simple function that returns the sum of the input values. It is realized as the function below. def summ(x,y): return x+y Unlike MATLAB or IDL, it is possible to execute a function in the Python shell. You may type the above function in a Python shell or an enhanced Python shell such as IPython. Once the ...

Ex:2 Familiarization of Scientific Computing

Iterations and Conditions in Python

Dr. Hari V S Department of Electronics and Communication College of Engineering Chengannur What You Will Learn You will learn the syntax of for, while loops and if statement in Python You will apply these to solve a mathematical problem. For loop Python identifies code blocks by indentation. The for loop has the syntax shown below. Observe the colon at the end of the first line and the indentation at the start of the second line. Whatever is to happen under the for loop should be given as an indented block. If the indentation is wrong, it raises an exception. for i in range(0,10): print i The above code prints the integers from 0 to 9. One can modify the above code for appending the values to a blank array as shown in the following code. from scipy import * arr=[] for i in range(0,10): arr.append(i) print arr The loops being slow, the above method is not encouraged. Instead, vectorized computation is used as shown below. from scipy impor...