Numerical Method Lecture 2 Numerical Method and Computer

  • Slides: 15
Download presentation
Numerical Method Lecture 2: Numerical Method and Computer Program By: Nur Uddin, Ph. D

Numerical Method Lecture 2: Numerical Method and Computer Program By: Nur Uddin, Ph. D 1

2

2

Computer Program • The real power of computers can only be utilized if you

Computer Program • The real power of computers can only be utilized if you can program them. • Programming consists of writing a set of instructions in a very specialized language that has adopted words and expressions from English. • Such languages are known as programming or computer languages. • The set of instructions (algorithm) is given to a program which can translate the meaning of the instructions into real actions inside the computer. 3

Computer language • Within the engineering area, the most widely used computer languages are

Computer language • Within the engineering area, the most widely used computer languages are Python, MATLAB, Octave, Fortran, C, C++, and to some extent Maple, and Mathematica. • Writing the instructions (i. e. the syntax) differs between the languages. 4

Python • Both Python and Matlab represent excellent programming environments for scientific and engineering

Python • Both Python and Matlab represent excellent programming environments for scientific and engineering tasks. • Some of Python’s strong properties deserve mention here: 1. Many global functions can be placed in only one file, functions are straightforwardly transferred as arguments to other functions. 2. Good support for interfacing C, C++ and Fortran code. 3. Functions explicitly written for scalar input often work fine (without modification) also with vector input. 4. Python is available for free. 5. Run on most platforms 5

A Python Program with Variables Predicts the position of a ball thrown up in

A Python Program with Variables Predicts the position of a ball thrown up in the air 6

Program script explanation • Comment • Assignment statement to variables • Mathematic operation (formula)

Program script explanation • Comment • Assignment statement to variables • Mathematic operation (formula) • Print the result 7

A Python Program with a Library Function 8

A Python Program with a Library Function 8

A Program with Vectorization and Plotting 9

A Program with Vectorization and Plotting 9

Import library or module The import statement constitutes a quick way of populating your

Import library or module The import statement constitutes a quick way of populating your program with all necessary functionality for mathematical computing and plotting. 10

Plotting commands 11

Plotting commands 11

Arithmetic operation • When the arithmetic operators +, -, *, / and ** appear

Arithmetic operation • When the arithmetic operators +, -, *, / and ** appear in an expression, Python gives them a certain precedence. • Python interprets the expression from left to right, taking one term (part of expression between two successive + or -) at a time. • Within each term, ** is done before * and /. • Consider the expression x = 1*5**2 +10*3 - 1. 0/4. 12

Float and integer Integer : x = 2 Float: x = 2. 0 13

Float and integer Integer : x = 2 Float: x = 2. 0 13

Array 14

Array 14

Input data 15

Input data 15