Tải bản đầy đủ (.pdf) (217 trang)

TÍNH TOÁN ỨNG DỤNG TRONG KTDKSlide tin học ứng dụng thầy tùng

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (11.3 MB, 217 trang )

APPLIED COMPUTING IN
PETROLEUM ENGINEERING

Pham Son Tung, Ph.D.
GEOPET, HCMUT, Vietnam

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

1


Lecturer’s Contact
 Name: Pham Son Tung
 Lecturer at Hochiminh city University of Technology,
Faculty of Geology & Petroleum Engineering, Department
of Drilling & Production.
 Office: 102B8
 Email:

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

2


Course Requirements
 Regular attendance in class (less than 3 absences)
 Taking notes (Important: knowledge given orally during


lecture will be officially accounted in the course,
moreover, sometimes erroneous slides are corrected
during lecture)
 Exercises in class
 Homework and assignments
 Personal computer with Excel
 Calculator
 Papers and pens/bics
2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

3


ABOUT THE COURSE
1

COURSE OBJECTIVES

2

COURSE CONTENT

3

REFERENCES

4


2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

4


Course Objectives
To provide essential background of numerical methods
using MATLAB and EXCEL to solve technical problems.
To provide practical guidelines for the application of

MATLAB and EXCEL in petroleum engineering.

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

5


Course Contents







Basic knowledge about MATLAB

Advanced issues and applications in MATLAB
Using toolboxes in MATLAB
Regression analysis
Using and exploiting EXCEL
Computing calculation in geology & petroleum
engineering

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

6


References
• Steve T.Karris, Numerical Analysis Using Matlab and Excel,
Orchard Publications, 2006
• Mitchell Bill: Advanced Oilwell Drilling Engineering Handbook &
Computer programs, Michell Engineering, USA, 1994
• Mark Austin, David Chancogn, Introduction to Engineering
Programming in C, MATLAB and JAVA, Wiley Pub. 1999
• Clever Moler, Engineering Problem Solving with Matlab, D.M.
Etter, Prentice Hall, 2005
• Lecture slides: this lecture handout was redacted by Dr. Mai Cao
Lan, then revised and completed by Dr. Pham Son Tung
2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

7



CHAPTER 1.
BASIC KNOWLEDGE
ABOUT MATLAB
11

2/15/2017

Overview of MATLAB

2

Basic operations, commands and functions

3
3
4

Programming in MATLAB
Basic graphic

4
5

Code structure
Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

8



Matlab - Background
Matlab = Matrix Laboratory
An interactive tool that is suitable for running
computations, drawing graphs and much more
(graphical interface)
A programming language for technical computing
(scripts)

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

9


Command Window

 The output is displayed

 Get the previous command by pressing up
arrow keyboard
 Can clear window using the command clc

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

10



Workspace Window

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

11


Command History Window

Command History Window

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

12


Matlab Arithmetic Operators
Plus
Unary plus
Minus
Unary minus
multiply
power
Backslash or left matrix divide


+
+
*
^
\

Slash or right matrix divide

/

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

13


Matlab Special Numbers
pi

3.14159265…

i and j

Imaginary unit

eps

Relative precision 2-52


realmin

Smallest number 2-1022

realmax

Largest number (2-eps)* 21023

Inf

Infinity

NaN

Not a Number

2/15/2017

(divide by zero or larger then realmax)
(0/0 Inf/Inf)

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

14


Lets Try Matlab as a Calculator II
2*5+10
2*(5+10)


What does it tell you? Evaluation

2/3*4

Operator evaluation priorities are mathematical

 1  3  2 3 4

(-1+3+2*pi)^(3/4)

1/0

What did you get? Inf NaN

0/0
1+2+3+4+5+6

Try to use … in order to write in more than one line

2*realmax

What did you get? Overflow

Try to use:
clc , up/down arrow
Usually a Matlab command ends with “;” to disable echo to the command line.
There are 3 ways to display the output: disp() , no “;” fprintf()
2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam


15


Using the Help
• Help:







Help (“help cos”);
lookfor
Doc (“doc cos”);
Search
F1 / right click
Google “matlab …”

• “Getting started”
• Matlab contains many
mathematical functions.
• Matlab is case sensitive!

2/15/2017

1. Search for “elementary
math functions reference”
and find the mathematical

function reference list
2. How do I calculate “square
root” ? Search...
3. What does the function
“factor” do?
4. What are the differences
between “ceil” “floor”, “fix”
and “round”? Try to run
“Fix” – what happened?

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

16


Output Format
• Use the format function to control the output
format of numeric values displayed in the
Command Window.




format short (5 digits) , format Long (15 digits) , format rat
Pi = 3.1416,
3.141592653589793 , 355/113

• format Compact / format loose – determines
the line spacing in the output
• Checkout the doc of “format” …

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

17


Current Directory Window

Current directory path
Current directory window
 Double click on a file will open it:
 .m file (script) in Editor/Debugger
 .fig file (figure) in Graphic window
 .mat file (data) will load variables to
the workspace

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

18


Changing The Current Directory
1
2

3
pwd – current path

cd – change directory
./ - current directory
../ - parent directory

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

19


Set Matlab Search Path
Matlab search for scripts and functions in:
Current directory.
 Path directories.


Can be done also using addpath, rmpath , path etc.
Matlab search order:
variables -> keywords -> current directory -> search path.

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

20


Editor / Debugger Window



open Editor: Desktop menu -> Editor
Save your script as helloWorld
run in the command window: helloWorld

disp(‘hello world’);

More:
Cntrl-C (editor / command win.), Cntrl-V,
Cntl-Z, Cntl-F, Cntrl-H
Comments % , %{ this is a comment %}
Case sensitive (and syntax errors)
2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

21


Desktop Layout
• Layout – the arrangement of the windows on
Any window on the upper right corner
the desktop

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

22



Standard Toolbar






Help
Window
Desktop
Edit
File

2/15/2017

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

23








A List Of Matlab Operators

Arithmetic operators.

plus
- Plus
+
uplus - Unary plus
+
minus - Minus
uminus - Unary minus
mtimes - Matrix multiply
*
times - Array multiply
*
mpower - Matrix power
^
power - Array power
.^
mldivide - Backslash or left matrix divide \
mrdivide - Slash or right matrix divide
/
ldivide - Left array divide
.\
rdivide - Right array divide
./
kron
- Kronecker tensor product
kron
Relational operators.
eq
- Equal
==
ne

- Not equal
~=
lt
- Less than
<
gt
- Greater than
>
le
- Less than or equal
<=
ge
- Greater than or equal
>=
Logical operators.
and - Logical AND
&
or
- Logical OR
|
not
- Logical NOT
~
xor
- Logical EXCLUSIVE OR
any - True if any element of vector is nonzero
all
- True if all elements of vector are nonzero

2/15/2017


Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

24


Basic graphic
1
0.8

How to draw a plot
How to control:

0.6
0.4
0.2

axis
Annotations: title, xlabel,
ylabel, legend
Line specifications:
Symbol
b
g
r
c
m
y
k


2/15/2017

Color
blue
green
red
cyan
magenta
yellow
black
v
^
<
>
p
h

0
-0.2
-0.4
-0.6
-0.8
-1

Symbol
Marker
.
point
o
circle

x
x-mark
+
plus
*
star
s
square
d
diamond
triangle (down)
triangle (up)
triangle (left)
triangle (right)
pentagram
hexagram

0

2

:
-.
--

4

6

8


Symbol
solid
dotted
dashdot
dashed
(none)

Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam

10

12

14

16

Line style

no line

25


×