Numerical Method Using Python: (MCSC-202)
Numerical Method Using Python: (MCSC-202)
(MCSC-202)
USING PYTHON
By
Samir Shrestha
Department of Mathematics
Kathmandu University, Dhulikhel
Lecture-1
Needs of Computer Program
Numerical Method deals with designing and analysis of
algorithm for numerical approximations of the problems
from mathematics that might not be solve exactly
Reference Books
About Python
Installation of Python
References
1. H. Bhasin, Python Basics A Self-Teaching Introduction, 2019
2. H. P. Langtangen, A Primer on Scientific Programming with Python,
2016
3. Jaan Kiusalaas, Numerical Methods in Engineering with Python 3, 2013
4. Robert Johansson, Numerical Python: Scientific Computing and Data
Science Applications with Numpy, SciPy and Matplotlib, 2019
5. https://www.javatpoint.com/python-tutorial
Languages
Languagage of Computer
Languages
Python C FORTRAN
Assembly Language
Machine Language
Hardware
COBOL
business data
LISP
logic and AI
BASIC
a simple language
7
Compiler
A compiler is a program that
reads a program written in the
high-level language and
converts it into the machine or
low-level language and reports
the errors present in the
program.
It converts the entire source
code in one go or could take
multiple passes to do so, but at
last, the user gets the compiled
code which is ready to execute.
Examples: C, C++, C#, Scala
8
Compiler: 6 Phases
Lexical Analyzer: Scans the code
as a stream of characters into
lexemes. Output: Sequence of
tokens with reference to the
programming language
Syntax Analyzer: Tokens
generated in Lexical analyzer
phase are against grammar of
programming language. Checks
whether the expressions are
syntactically correct or not. It
makes parse trees
9
Compiler: 6 Phases
Semantic Analyzer: Checks
whether the expressions and
statements generated by
previous phase follow the rule of
programming language or not.
Creates annotated parse trees
Intermediate Code: Equivalent
intermediate code of the source
code.
Code Optimizer: Improves space
and time requirement of the
program. Eliminates the
redundant code
10
Compiler: 6 Phases
11
Interpreter
17
Python Features
Easy to Learn and Use: It is developer-friendly and high level
programming language
Python is an interpreted language : Interpreter executes the code line by
line at a time. This makes debugging easy and thus suitable for beginners.
Cross-platform Language: Python can run equally on different platforms
such as Windows, Linux, Unix and Macintosh etc. So, we can say that
Python is a portable language
Free and Open Source: Python language is freely available at offical web
address. The source-code is also available.
Object-Oriented Language: Python supports object oriented language
and concepts of classes and objects come into existence
Extensible: If needed, one can write some of the Python code in other
languages line C++. This makes Python an extensible language
Large Standard Library: Python has a large and broad library and provides
rich set of module and functions for rapid application development
GUI Programming Support: Graphical user interfaces can be developed
using Python
Integrated: It is also possible to put our Python code in a source code in
a different language like C++
18
Why Python
19
Python Libraries
numpy: Multi-dimensional array
operations
matplotlib: plotting library
130K+ packages scipy: scientific computing
2K packages per pandas: data frame, data manipulation
month and analysis
• seaborn: For visualization of statistical
181657 projects data
• statsmodels: For statistical modeling and
advanced analysis
Symby: symbolic computation
SageMath: System of Algebra and
Geometry Experimentation
Python Libraries
PiCloud: Supercomputing
Many aspects processing capacity on the
Mathematics cloud
Algebra Scikit-learn: Machine Learning
toolkit
Combinatorics
Pygame: For game
Numerical development
Mathematics pyQT/pyGtk: To develop GUI
Calculus Nltk: natural language kit
Number theory TensorFlow: machine learning
library
Keras: machine learning library
Applications for Python
22
Applications for Python
Python Installation
Two different ways out of many
Recommended version 3
24
Python Installation
25
Python Installation
https://www.python.org/
26
Python Installation
https://www.python.org/
Click
27
Python Installation
https://www.python.org/downloads/
28
Python Installation
https://www.python.org/downloads/
29
Basics
Console: The text box onto which output is printed.
Some source code editors pop up the console as an
external window, and others contain their own console
window.
31
Python Editor Python IDLE
Figure as a output
32
Python Installation
Download python from Anaconda
Distributions:
https://www.anaconda.com/products/individual
Recommended version 3.7
Scroll down
34
Anaconda Navigator
After installation
35
Anaconda Navigator
After installation
36
Spyder
Python IDE - Spyder
37
Spyder
Python IDE - Spyder
38
Jupyter Notebook
Web-based, interactive computing notebook environmnt
39
Jupyter Notebook
Web-based, interactive computing notebook environmnt
40
End of Lecture-1
Lecture-2
Data Types, Operators, Math
Functions,
41