13/14 Semester 1 Computer Programming (TKK-2144) Instructor: Rama Oktavian Email: rama.oktavian@ub.ac.id Office Hr.: M.13-15, W. 13-15 Th. 13-15, F. 13-15 Outlines 1. Microsoft Excel basic function 2. Matrix (basic theory) 3. Matrix operation in excel 4. The application of Matrix in Chem. Eng Basic function Using Relative References Cell references are used in formulas, functions, charts , and other Excel commands. By default, a spreadsheet cell reference is relative. What this means is that as a formula or function is copied and pasted to other cells, the cell references in the formula or function change to reflect the function's new location. Basic function Using Absolute References an absolute cell reference identifies the location a cell or group of cells. An absolute cell reference consists of the column letter and row number surrounded by dollar signs ( $ ). An absolute cell reference is used when you want a cell reference to stay fixed on a specific cell. Basic function Using Mixed references Basic function Entering Relative, Absolute, and Mixed References To enter a relative reference, type the cell reference as it appears in the worksheet. For example, enter B2 for cell B2 To enter an absolute reference, type $ (a dollar sign) before both the row and column references. For example, enter $B$2 To enter a mixed reference, type $ before either the row or column reference. For example, enter $B2 or B$2 or Select the cell reference you want to change Press the F4 key to cycle the reference from relative to absolute to mixed and then back to relative Basic function -Mathematics function - Statistical function - Logical function - etc Basic function Mathematics functions abs(CELL): Absolute value of CELL sqrt(CELL): Square root of CELL [to do nth roots, use CELL^(1/n)] ln(CELL): Natural log of CELL log10(CELL): Log of CELL to base 10 log(CELL, NUM): Log of CELL to the base NUM (use for all bases except e and 10) exp(CELL): Exponential(e^x) of CELL. Use since Excel doesn't have a builtin constant "e". sin(CELL), cos(CELL), tan(CELL): Trigonometric functions sine, cosine, and tangent of CELL. CELL must be in radians asin(CELL), acos(CELL), atan(CELL): Inverse trigonometric functions (returns values in radians) sinh(CELL), cosh(CELL), tanh(CELL): Hyperbolic functions asinh(CELL), acosh(CELL), atanh(CELL): Inverse hyperbolic functions Basic function Statistical functions average(CELL1, CELL2, ...) OR average(GROUP): Computes the arithmetic average of all inputs intercept(GROUP1, GROUP2): Calculates the y-intercept (b) of the regression line where y = GROUP1 and x = GROUP2 slope(GROUP1, GROUP2): Calculates the slope (m) of the regression line where y = GROUP1 and x = GROUP2. “if” function Working with Logical Functions A logical function is a function that works with values that are either true or false The IF function is a logical function that returns one value if the statement is true and returns a different value if the statement is false IF(logical_test, value_if_true, [value_if_false]) “if” function Working with Logical Functions A comparison operator is a symbol that indicates the relationship between two values “if” function Working with Logical Functions =IF(A1="YES", "DONE", "RESTART") =IF(A1="MAXIMUM", MAX(B1:B10), MIN(B1:B10)) =IF(D33>0, $K$10, 0) “if” function Working with Logical Functions Matrix (basic theory) Matrix Mathematics Matrices are very useful in engineering calculations. For example, matrices are used to: - Efficiently store a large number of values -Solve systems of linear simultaneous equations Several mathematical operations involving matrices are important Matrix (basic theory) Review: Properties of Matrices • An element of a matrix is usually written in lower case, with its row number and column number as subscripts: • The dimension (size) of a matrix is defined by the number of rows and number of columns • Examples: 3 × 3: 2×4: Matrix (basic theory) Matrix Operations • • • • • • Matrix Addition Multiplication of a Matrix by a Scalar Matrix Multiplication Matrix Transposition Finding the Determinate of a Matrix Matrix Inversion Matrix (basic theory) Matrix Addition • Vectors must be the same size in order to add • To add two vectors, add the individual elements: • Matrix addition is commutative: A+B=B+A Matrix (basic theory) Multiplication of Matrices • To multiple two matrices together, the matrices must have compatible sizes: This multiplication is possible only if the number of columns in A is the same as the number of rows in B • The resultant matrix C will have the same number of rows as A and the same number of columns as B Matrix (basic theory) Multiplication of Matrices • Consider these matrices: • Can we find this product? Yes, 3 columns of A = 3 rows of B • What will be the size of C? 2 X 2: 2 rows in A, 2 columns in B Matrix (basic theory) Example – Matrix Multiplication • Solution: In general, matrix multiplication is not commutative: AB ≠ BA Matrix (basic theory) Transpose of a Matrix • The transpose of a matrix by switching its row and columns The transpose of a matrix is designated by a superscript T: Matrix (basic theory) Determinant of a Matrix • The determinant of a square matrix is a scalar quantity that has some uses in matrix algebra. Finding the determinate of 2 × 2 and 3 × 3 matrices can be done relatively easily: • The determinate is designated as |A| or det(A) • 2 × 2: Matrix (basic theory) Determinant of a Matrix • 3 × 3: Matrix (basic theory) Inverse of Matrix • The inverse of a 2X2 matrix is easy to find: Matrix (basic theory) The identity matrix • a square matrix with 1’s as the diagonal elements and 0’s as the other elements • Find A-1, check that A A-1 = I Matrix Operations in Excel • Excel has commands for: • • • • Multiplication (mmult) Transpose (transpose) Determinate (mdeterm) Inverse (minverse) • Important to remember that these commands apply to an array of cells instead of to a single cell • When entering the command, you must identify the entire array where the answer will be displayed • Using the Enter key with an array command only returns an answer in a single cell. Instead, use Ctrl + Shift + Enter keys with array functions Matrix Operations in Excel Excel Matrix Multiplication Matrix Operations in Excel Excel Matrix Multiplication The MMULT function has two arguments: the ranges of cells to be multiplied. Remember that the order of multiplication is important. Matrix Operations in Excel Excel Transpose Matrix Operations in Excel Excel Determinate Matrix Operations in Excel Excel Matrix Inversion Remember that only square matrices can have inverses Matrix Operations in Excel Excel Matrix Inversion A X A-1 = I, the identity matrix: The application of Matrix Solving linear simultaneous equation • If equations contain only linear terms of the independent variables – that is, only constants multiplied by each variable – and constants, then the equation is linear • If the equation contains any terms such as x2, cos(x), ex, etc., then the equation is non-linear Linear simultaneous equation The application of Matrix Solution to Simultaneous Equations • Graphical solution • Substitution method • Elimination method The application of Matrix Equations in Matrix Form • The first step in using matrix methods to solve a series of linear simultaneous equations is to write them in matrix form • For n simultaneous equations and n unknowns: where A is the coefficient matrix (n × n); X is the matrix of unknowns (n × 1), and C is the constant matrix (n × 1) The application of Matrix Solution of System of Linear Equations Multiply both sides of the equation by the inverse of the coefficient matrix. Remember that the order of multiplication is important. Since the inverse of a matrix times that matrix is equal to the identity matrix, The application of Matrix Solution of System of Linear Equations Since the identity matrix times another matrix is equal to that matrix, Therefore, we can find the unknown variables by multiplying the inverse of the coefficient matrix by the constant matrix The application of Matrix Example – 3 Equations Write these equations in matrix form: The application of Matrix Excel Solution Enter coefficient and constant matrices: The application of Matrix Excel Solution Enter formula to invert A matrix and multiply the result by the C matrix. This can be done in two steps or with nested commands as shown here: The application of Matrix Chem. Eng Problem Steady state material balances on a separation train Xylene, styrene, toluene and benzene are to be separated with the array of distillation columns that is shown below where F, D, B, D1, B1, D2 and B2 are the molar flow rates in mol/min. The application of Matrix Chem. Eng Problem Solution Material balances on individual components on the overall separation train yield the equation set The application of Matrix