Applied computing in petroleum engineering - Pham Son Tung

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 
pdf 217 trang thamphan 26/12/2022 4020
Bạn đang xem 20 trang mẫu của tài liệu "Applied computing in petroleum engineering - Pham Son Tung", để tải tài liệu gốc về máy hãy click vào nút Download ở trên.

File đính kèm:

  • pdfapplied_computing_in_petroleum_engineering_pham_son_tung.pdf

Nội dung text: Applied computing in petroleum engineering - Pham Son Tung

  1. Epilogue - Solving Linear Systems of Equations Say we want to solve the following system: a11x1 a12 x2 a13x3 b1 a21x1 a22 x2 a23x3 b2 Ax=b a31x1 a32 x2 a33x3 b3 A = [ 1 1 1 ; 1 2 3 ; 1 3 6 ]; b = [3; 1; 4]; x = A\b; Solution: x = 10 -12 5 More: search help “solving linear equations” 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 93
  2. Summary Introduce the Notion of Variables & Data Types. Master Arrays manipulation Learn Arrays Mathematical Operations Learn Simple String Manipulations Learn to Use Array Editor Solving Linear System of Equations 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 95
  3. Lecture Reminder 1 0.8 How to draw a plot 0.6 0.4 How to control: 0.2 0 axis -0.2 Annotations: title, xlabel, -0.4 -0.6 ylabel, legend -0.8 -1 Line specifications: 0 2 4 6 8 10 12 14 16 Symbol Color Symbol Marker Symbol Line style b blue . point - solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus dashed m magenta * star (none) no line y yellow s square k black d diamond v triangle (down) ^ triangle (up) triangle (right) p pentagram h hexagram 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 97
  4. The Basic Components of a Figure x = linspace(0,2*pi,101); y = sin(x); # - A figure handle figure; plot(x,y); Menu & Toolbar n = figure; creates a new figure figure(n); makes figure “n” the current figure The current figure is the target of the graphics output! There are many options to edit the figure from the toolbar Axes - a graphical object that Plot Axes contains graphs. Plot of a data series 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 99
  5. Lets Make Our Sine Plot Good Looking Controlling line properties specifications Annotating the graph Basic plot: Legend figure; plot(x,y); Title Axes labels Adding text Controlling the axes limits Most of the functions are applicable to other types of graphs! 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 101
  6. Setting Line properties Graphics elements are plot(x,y, 'ro:', 'LineWidth',3, represented by “objects” 'MarkerEdgeColor','k', For example a data series 'MarkerFaceColor',[.49 1 .63], line is an “object” 'MarkerSize',10); We can change a property of an object by passing to the function: The property name as a string The property value Colors can be represented as RGB combination [R,G,B] 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 103
  7. Adding Text to Graphs plot(x,y, 'ro:', 'LineWidth',3, 'MarkerEdgeColor','k', 'MarkerFaceColor',[.49 1 .63], 'MarkerSize',12); title('A Sine Plot', X coordinate 'FontSize', 16, 'FontWeight', 'bold'); xlabel('Angle (radians)'); ylabel('Value'); Y coordinate legend('Sine'); text(pi/6, sin(pi/6), ['sin(\pi/6) = ' num2str(sin(pi/6))], 'FontSize', 14); 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 105
  8. Get/Set – Modifying the Ticks and Ticks Labels plot(x,y, 'ro:', 'LineWidth',3, 'MarkerEdgeColor','k', 'MarkerFaceColor',[.49 1 .63], 'MarkerSize',12); title('A Sine Plot', 'FontSize', 16, 'FontWeight', 'bold'); xlabel('Angle (radians)'); ylabel('Value'); legend('Sine'); text(pi/6, sin(pi/6), ['sin(\pi/6) = ' num2str(sin(pi/6))],'FontSize', 14); axis([0 pi -1 1 ]) box off grid on; x_labels = char('0 degrees','90 degrees','180 degrees'); set(gca, 'XTick', [0, pi/2, pi]) set(gca, 'XTickLabel', x_labels) Property Value 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 107
  9. Saving Figure Formats: .fig format; fig, Save using: bmp,  Figure menu -> File -> save / save as , chose format jpg,  Use save or saveas function: eps, x = linspace(0,2*pi,41); tif, y = sin(x); more figure_h = figure; plot(x,y) saveas(figure_h, 'sine', 'jpg');% gcf 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 109
  10. 2D Graphics Review 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 111
  11. Hist /Histc x=-3:0.1:3; y = randn(1,1000); # bins figure; subplot(3,1,1); hist(y,50); title('hist - k bins'); subplot(3,1,2); Centers of bins hist(y,x); title('hist - bin centers given by x'); subplot(3,1,3); edges of bins [n,bin] = histc(y,x); n=n/sum(n); Converting to percent bar(x,n); title('histc & bar'); of values Bin index for each element 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 113
  12. Errorbar & pie figure; Like plot but with error bars errorbar(x,y,e); title('errorbar'); a = [ 10 , 5 , 20, 30] figure; subplot(2,1,1); Explode – logical array pie(a, [0,0,0,1]); legend('A','B','C','D') subplot(2,1,2); pie3(a, [0,0,0,1]); legend('A','B','C','D'); 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 115
  13. Exercise – Lets Draw the Following Figure std Title – font size=16 Axis labels – font size=14 Line width 2 20 bins Fraction Tight Tip – manually move the legend 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 117
  14. Draw the First Graph - errorbar Data analysis avg_price_per_year = mean(gasoline_prices,2); std_price_per_year = std(gasoline_prices,0,2); Draw figure; errorbar(years, avg_price_per_year, std_price_per_year, 'r-', 'LineWidth',2); xlabel('Year', 'FontSize', 14) ylabel('$/Gallon', 'FontSize', 14); title('Gas Price', 'FontSize', 16); 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 119
  15. Draw the Second Graph – multiple plots Data analysis gas_price_90 = gasoline_prices(find(years == 1990),:); gas_price_95 = gasoline_prices(find(years == 1995),:); gas_price_00 = gasoline_prices(find(years == 2000),:); Draw plot(1:12,gas_price_90, 'r-x','LineWidth',2); hold on; plot(1:12,gas_price_95, 'b:o','LineWidth',2); plot(1:12,gas_price_00, 'g ^','LineWidth',2); hold off; xlabel('Month', 'FontSize', 14); ylabel('$/Gallon', 'FontSize', 14); title('Monthly Prices at 1990, 1995, 2000', 'FontSize', 16); legend('1990','1995','2000'); set(gca,'XTick',1:12, 'XTicklabel', months); grid; axis tight; 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 121
  16. Draw the Third Graph – hist / bar Data analysis [n xout] = hist(gasoline_prices(:), 20); n = n/sum(n); Draw bar(xout,n); ylabel('Fraction', 'FontSize', 14); xlabel('$/Gallon', 'FontSize', 14); title('Monthly price distribution', 'FontSize', 16); axis tight; 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 123
  17. 2D Graphics Summary data analysis is very easy with matlab: min, max, median, std Figure can contain several axes (subplots) which can hold several data sets each Learn how to visualize data Draw 2D graphs Control graphs properties & annotate graphs Draw 3D graphs Create movies 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 125
  18. 3D plot – plot3 Several graphs have a z 3D equivalent. 1 y Much of what we 1 learned for 2D graph x1 holds in 3D t = 0:pi/50:10*pi; plot3(sin(t),cos( t),t) grid on axis square 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 127
  19. Running example ( x2 y2 ) Consider the function: f (x, y) xe Draw a mesh graph of the function in the range: xx = - 2:.2:2 , yy = -2:.2:3 What is the difference between mesh and surf? Try also:  meshz(X,Y,Z); xx = -2:.2:2;  meshc(X,Y,Z); yy = -2:.2:3;  surfc(X,Y,Z); [X,Y] = meshgrid(xx,yy);  contour(X,Y,Z);  contour3(X,Y,Z); Z = X.*exp(-X.^2-Y.^2);  contourf(X,Y,Z); Play with colormap and add color bar 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 129
  20. More About 3D graphs figure; subplot(2,2,1); Z_tag = Z; Z_tag(6:11,6:11) = NaN; surf(X,Y,Z_tag); title('surf with NaNs'); subplot(2,2,2); [dX,dY] = gradient(Z,.2,.2); contour(X,Y,Z), hold on, quiver(X,Y,dX,dY), hold off title('contour & quiver (of gradient)'); subplot(2,2,3); surf(X,Y,Z); title('surf, head camlight, phong lighting '); camlight headlight; lighting phong; subplot(2,2,4); surf(X,Y,Z);title('surf, view Az=27, El=52'); view(27,52); The graphs can be also rotated with the figure toolbar 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 131
  21. Twin Peaks xx = -2:.2:2; yy = -2:.2:3; [X,Y] = meshgrid(xx,yy); Z = X.*exp(-X.^2-Y.^2); clear F; j = 1; surf(X,Y, sin(2*pi*j/20)*Z); zlim([-0.4218 0.4218]); F(j) = getframe; j = 20; surf(X,Y, sin(2*pi*j/20)*Z); Play the movie ten times zlim([-0.4218 0.4218]); movie(F,10); F(j) = getframe; % create an avi movie Try it yourself! movie2avi(repmat(F,1,5), (remember ctrl-C to stop the movie) 'twin_peaks.avi', 'compression’, 'Indeo3' ); 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 133
  22. Exercise 3. • Write a function : function [D,E,F] = createspecialarrays(M,N) which creates three arrays. D should be M × N (M rows, N columns) filled with 0’s , E should be M ×M filled with 3’s, and F should be N × N with 5’s on the diagonal. For instance, if M = 2 and N = 3, you would have the arrays: • Then write a script which calls your function createspecialarrays for M=3 and N=2 and displays the outputs D, E, and F.
  23. Exercise 5.
  24. Exercise 7.
  25. Exercise 8.
  26. Exercise 9. Using the Euler Forward scheme to solve this following ODE: Repeat the same question but this time using: - Euler Backward method - Crank-Nicolson method - dsolve
  27. Question 1: 3 points Question 2: 3 points Question 3: 4 points
  28. Attention: all 3 plots must be in the same Figure with different colors. Title, Labels and Legend must be included.
  29. CHAPTER 3. USING TOOLBOXES GUI IN MATLAB 11 Introduction about toolboxes GUI in MATLAB 2 Toolbox GUI for statistics 3 Toolbox GUI for PDE 3 4 5 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 149
  30. MATLAB Toolboxes  PRTools Toolbox: Includes algorithms for data generation, training classifiers, features selection, density estimation, feature extraction, cluster analysis.  Statistical Pattern Recognition Toolbox: It provides users with procedures for discriminant functions, feature extraction, density estimation, support vector machines, visualization, regression, etc
  31. MATLAB Toolboxes  PCNN Toolbox  SDH Toolbox  SOM Toolbox  SSVM Toolbox  SVM Toolbox  SVM Classifier Toolbox  Bioinformatics Toolbox
  32. PDE Toolbox GUI • pdetool
  33. REGRESSION ANALYSIS  Introduction about regression analysis  Linear regression  Polynomial regression  Power regression  Exponential regression Copyright 2015 HỒI QUY THỰC NGHIỆM 157
  34. INTRODUCTION  Data analysis  Correlation: . Statistical relationship between two variables . X ↔ Y: n data set (x1, y1), (x2, y2), (xn, yn) . Coefficient of Correlation: Correlation coefficient varies between +1 and −1 inclusive, where 1 is total positive correlation, 0 is no correlation, and −1 is total negative correlation Copyright 2015 HỒI QUY THỰC NGHIỆM 159
  35. INTRODUCTION  Data analysis  Correlation  Prediction: . A relationship model between 2 variables can be built . Choice of type of model is important . The model helps to predict: X → Y − X : independent variable, predictor variable − Y : dependent variable, response variable Copyright 2015 HỒI QUY THỰC NGHIỆM 161
  36. LINEAR REGRESSION  Objective : modelling a relationship between one or multiple independent variables Xi and one dependent variable Y  One independent variable: Simple linear regression  Multiple independent variables: Multiple linear regression  General form of multiple linear regression: ў = a0 + a1x1 + a2x2 + + amxm Example: x1 is Age, x2 is Weigh, x3 is Height, y is Cholesterol concentration in blood Copyright 2015 HỒI QUY THỰC NGHIỆM 163
  37. LEAST SQUARES METHOD  Least squares formulation: n 2 ˆ  []yyjj j 1 n 2 [yjj f ( x1 , x 2 , , a 0 , a 1 , a 2 ) ] min j 1  yj (j=1:n): experimental dependent data  ўj : predicted data  n: number of data set  xi (i=1:m): experimental independent data Copyright 2015 HỒI QUY THỰC NGHIỆM 165
  38. LEAST SQUARES METHOD  We have:  y j j  y j x1 j j . Vector; B  y j x2 j j  y x  j mj j . Matrice A (m+1,m+1) N  x1 j  x2 j   xmj 2  x1 j  x1 j  x2 j x1 j   xmj x1 j A x x x x 2 x x  2 j  1 j 2 j  2 j  mj 2 j  2  xmj  x1 j xmj  x2 j xmj   xmj . Replace (a0, a1, a2, , am) into the model and we can have graphical presentation for the experimental data set {(yj,x1j,x2j, ,xmj), j=1:n} Copyright 2015 HỒI QUY THỰC NGHIỆM 167
  39. LINEAR REGRESSION  Exercise: for a experimental data set of two variables X and Y i X Y 1 2 66 2 19 77 3 6 37 4 23 106 5 10 55 6 23 89 7 9 52 8 30 128 9 18 63 10 25 104 11 19 76 12 2 44 13 27 97 14 28 109 15 8 40 16 29 124 17 29 98 18 16 63 19 33 131 20 3 41 21 34 111 22 32 151 23 13 76 24 33 114 25 35 143 Copyright 2015 HỒI QUY THỰC NGHIỆM 169
  40. LINEAR REGRESSION  Exercise: J (hydraulic inclination) and V (cm/d) permeability: J 7 9 12 15 18 V (cm/d) 0,5 2 6,5 9,5 14 V (cm/d) 16 12 V = 1.2373J - 8.5952 8 4 0 J 0 5 10 15 20 Copyright 2015 HỒI QUY THỰC NGHIỆM 171
  41. POLYNOMIAL REGRESSION  Exercise: material strength test experimental data Stress(ksi) Strain (in./in.) Stress(ksi) Strain (in./in.) Test Test Y X Y X 1 91 0.001 6 110 0.006 2 97 0.002 7 112 0.009 3 108 0.003 8 105 0.011 4 111 0.005 9 98 0.016 5 114 0.006 10 91 0.017  Knowing that Stress and Strain have a parabolic relationship. 120 y = -311829x2 + 5378x + 89.583 110 100 Stress (ksi) Stress 90 80 0 0.005 0.01 0.015 0.02 Strain (in./in.) Copyright 2015 HỒI QUY THỰC NGHIỆM 173
  42. POWER REGRESSION  Exercise: . Shear stress and shear velocity of a circulation mud: yˆ 2.896 0.2031x  18.108  0.2031 80 70 60 50 40 30 20 10 0 0 200 400 600 800 1000 1200 Copyright 2015 HỒI QUY THỰC NGHIỆM 175
  43. EXPONENTIAL REGRESSION  Exercise: computer chess skill data analysis Number Skill of Games Index lnY XlnY X2 X Y 3 2.773 8.318 9 7 16 3.526 24.685 49 8 34 3.689 29.511 64 12 40 4.533 54.391 144 14 93 4.828 67.596 196 9 125 3.912 35.208 81 9 50 3.871 34.841 81 4 48 2.890 11.561 16 11 18 4.248 46.733 121 13 70 4.700 61.106 169 12 110 4.443 53.312 144 8 85 3.807 30.453 64 7 45 3.689 25.822 49 6 40 3.497 20.979 36 3 33 2.996 8.987 9 126 20 57.402 513.505 1232 =X =lnY =XlnY =X2 Copyright 2015 HỒI QUY THỰC NGHIỆM 177
  44. CHAPTER 5. USING AND EXPLOITING EXCEL 11 Overview 2 Data and spreadsheet formats 3 Basic operations, commands, functions, calculations 3 4 Charts 4 5 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 179
  45. What is a COLUMN ? In a spreadsheet the COLUMN labeled D is COLUMN is defined as highlighted. the vertical space that is going up and down the window. Letters are used to designate each COLUMN'S location.
  46. What is a CELL ? A CELL is the space In the above diagram where a row and the CELL labeled C2 is column intersect. Each highlighted. CELL is assigned a name according to its COLUMN letter and ROW number.
  47. Labels Labels are text entries Labels help identify what we are talking about Labels do not have a value associated with them Sometimes called ‘headers’
  48. Formulas Formulas are math equations that CALCULATE a value to be displayed. DO NOT type in the numbers; type in the equation. It is BEST to Reference as much data as possible as opposed to typing data into equations. That way when OTHER information changes, we DO-NOT have to change the equations or type in information again.
  49. Basic Math Functions Math functions built into them. Of the most basic operations are the standard multiply, divide, add and subtract.
  50. Sum function
  51. Max & Min Functions The Max function will return the largest (max) value in the selected range of cells. The Min function will display the smallest value in a selected set of cells.
  52. IF Function Definition: Tips: The IF function will check Until you are used to the logical condition of a writing them, test them statement and return one out on multiple cells. value if true and a There are multiple ways to different value if false. write an IF statement to The syntax is: get the same result =IF (condition, value-if- true, value-if-false)
  53. Concatenate function Concatenate function - join several strings into one text string Note: The concatenateSyntax: function does not automatically leave=A1&A2 a blank space between words or other data.
  54. Removing duplicate values Removing duplicate values – check for and delete specific cells with duplicate values
  55. Instantly reveal formulas and general number format of all cells Show all formulas and the general number format of cells Saves you time because you don’t have to move the cell pointer to check each formula one-by- one.
  56. Comparing 2 or more Excel spreadsheets simultaneously You can open two instances of Excel INSTEAD of multiple files on top of each other in the same Excel application. To do this, simply open Excel by double clicking the icon on your desktop and open the first Excel file you want to use. Minimize this window and move it to the right screen. Then go back to the desktop, double click the Excel icon once more, another separate Excel window will open.
  57. Filters The Filter is a quick and easy way to find and work with a subset of data in a range of cells.
  58. Elements of an excel table Header row By default, a table has a header row. Every table column has filtering enabled in the header row so that you can filter or sort your table data quickly.
  59. Elements of an excel table Total row You can add a total row to your table that provides access to summary functions (such as the AVERAGE, COUNT, or SUM function). A drop-down list appears in each total row cell so that you can quickly calculate the totals that you want.
  60. Freeze Headers To freeze a row in your worksheet, highlight the row where you wish all rows before the highlighted row to be frozen or locked, go to Window>Freeze Panes and you will see a line appear across your worksheet. Everything above the line is frozen and will remain in view when you scroll down your worksheet.
  61. Narrow margins
  62. Pivot Table A Pivot table lets your arrange, sort, and filter a set of data on the fly so you can analyze it from different perspectives with minimum effort. Start with a data list with a few columns Make sure each of the rows have a value of each one of the columns
  63. CHAPTER 6. COMPUTING CALCULATIONS IN GEOLOGY & PETROLEUM ENGINEERING 11 Application of Excel in Geology & Petroleum Engineering 2 MATLAB in Geology & Petroleum Engineering 3 Some software uses in Geology & Petroleum Engineering 3 4 Exercises / Group Exercises 4 5 2/15/2017 Pham Son Tung, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 217