TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES 363 P. Casal St., Quiapo, Manila CHEP 530D1 COMPUTER APPLICATIONS IN CHEMICAL ENGINEERING Bautista, Keziah Lynn S. Laboratory Exercise No. 1 Familiarization with Matlab Environment, November 9, 2013 Built-in Functions, Matrices and Plotting 1
Matlab is a powerful language for technical computing. Its basic data element is matrix (array).It can be used for math computations, modeling and simulations, data analysis and processing, visualization and graphics, and algorithm development. The standard Matlab program has tools (functions) that can be used to solve common problems. The array is a fundamental form that Matlab uses to store and manipulate data. An array is a list of numbers arrange in rows or in columns. The simplest array (one-dimensional) is a row, or a column of numbers. A more complex array (two-dimensional) is a collection of numbers arranged in rows and columns. One use of array is to store information and data, as in a table. In science and engineering, one-dimensional arrays frequently represent vectors and two-dimensional arrays represent matrices. Once variables are created in Matlab they can be used in a wide variety of mathematical operations. Matlab is designed to carry out advanced array operations that have many applications in science and engineering. Addition and subtraction are simple operations. The other basic operations, multiplication, division and exponentiation can be done in Matlab in two different ways. One way, which uses the standard symbols (*,/ and ^), follows the rules of linear algebra. The second way, which is called element-by-element operations, uses the symbols .*,./ and .^ ( a period is typed in front of the standard operation symbol).In both types of calculations, Matlab has left division operator (.\ or \).
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES363 P. Casal St., Quiapo, Manila
CHEP 530D1
COMPUTER APPLICATIONS IN
CHEMICAL ENGINEERING
Crispulo G. MarananInstructor
Laboratory Exercise No. 1Familiarization with Matlab Environment, Built-in Functions, Matrices and Plotting
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
1
1. Objective(s):The activity aims to familiarize the students with matlab environment, built-in functions, matrices and plotting.2. Intended Learning Outcomes (ILOs):
The students shall be able to:2.1 get acquainted with matlab environment and its various features.2.2 understand the built-in functions of matlab.2.3 Operate on the matrices.2.4 Plot different graphs using matlab.
3. Discussion: Matlab is a powerful language for technical computing. Its basic data element is matrix (array).It can be used for math computations, modeling and simulations, data analysis and processing, visualization and graphics, and algorithm development.
The standard Matlab program has tools (functions) that can be used to solve common problems.The array is a fundamental form that Matlab uses to store and manipulate data. An array is a list
of numbers arrange in rows or in columns. The simplest array (one-dimensional) is a row, or a column of numbers. A more complex array (two-dimensional) is a collection of numbers arranged in rows and columns. One use of array is to store information and data, as in a table. In science and engineering, one-dimensional arrays frequently represent vectors and two-dimensional arrays represent matrices.
Once variables are created in Matlab they can be used in a wide variety of mathematical operations. Matlab is designed to carry out advanced array operations that have many applications in science and engineering. Addition and subtraction are simple operations. The other basic operations, multiplication, division and exponentiation can be done in Matlab in two different ways. One way, which uses the standard symbols (*,/ and ^), follows the rules of linear algebra. The second way, which is called element-by-element operations, uses the symbols .*,./ and .^ ( a period is typed in front of the standard operation symbol).In both types of calculations, Matlab has left division operator (.\ or \).
4. Resources:Matlab
5. Procedure:1.Identify the different matlab windows and write its corresponding purpose.2.Note the different symbols used in the command window and write its corresponding use.3.Use matlab as a calculator and show the results in the accompanying table.4.Note the different built-in functions and show the results in the accompanying table.5.Evaluate the results after pressing the enter key for the assignment operator (=).6.Evaluate the results after pressing the enter key for the creation of vectors (row vector and column vector) from a known list of numbers, with constant spacing by specifying the first term, the spacing, and the last term, with constant spacing by specifying the first and last terms,and the number of terms7.Evaluate the results after pressing the enter key for the creation of two-dimensional array (matrix).8.Evaluate the results after pressing the enter key using colon (:) in addressing arrays.9. Identify the different built-in functions for handling array and indicate its description and give an example.10.Evaluate the results after pressing the enter key that involves strings and strings as variables.11. Evaluate the results after pressing the enter key that involves the operations of matrices.12.Evaluate the values of x, y and z of the three equations three unknowns :
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
2
4x – 2y + 6z = 82x + 8y + 2z = 46x + 10y + 3z = 0
13.Evaluate the results after pressing the enter key that involves element-element operations.14.Identify the different built-in functions for analyzing arrays and indicate its description and give an example.
Course: Laboratory Exercise No.:1Group No.: Section:CH51FA1Group Members: Date Performed: November 9, 2013
Date Submitted: November 11, 2013Instructor:Engr. Crispulo Maranan
6. Data and Results:1.
Window Purpose1.Command Window Inputs the commands to be use. It is used to
execute commands or aliases directly in the
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
3
Visual Studio integrated development environment (IDE). You can execute both menu commands and commands that do not appear on any menu. To display the Command window, choose Other Windows from the View menu, and select Command Window.
2.Figure Window It is directed to a window that is separate from the Command Window. This window is referred to as a figure. The characteristics of this window are controlled by your computer's windowing system and MATLAB figure properties.
3.Editor Window It is to create your own custom editor window that can float free or be docked as a tab, just like the native windows in the Unity interface. Editor windows are typically opened using a menu item.
4.Help Window Helps you about the commands and other terms to be used.
5.Launch Pad Window Access help, tools, demos and documentation6.Command History Compiles the history of the commands7.Workspace Window It consist of common mathematical figures,
graphs, etc.8.Current Directory The directory (folder) that MATLAB is currently
working in. This is where anything you save will go by default, and it will also influence what files MATLAB can see. You won't be able to run a script that you saved that you saved in a dierent directory.
element comparisons between two arrays. They return a logical array of the same size, with elements set to logical 1 (true) where the relation is true, and elements set to logical 0(false) where it is not.
; Used inside brackets to end rows. sssUsed after an expression or statement to suppress printing or to separate statements.
% Percentage. Used to indicate that the number preceding it should be understood as a
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
4
proportion multiplied by 100clc It clears all input and output from the Command
Window display, giving you a "clean screen."After using clc, you cannot use the scroll bar to see the history of functions, but you still can use the up arrow key, ↑, to recall statements from the command history.
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
14
reshape(A,m,n) B = reshape(A,m,n) returns the m-by-n matrix B whose elements are taken columnwise from A. An error results if A does not have m*n elements.
median(A) It returns the median value of A. Define a 4-by-3 matrix.A = [0 1 1; 2 3 2; 1 3 2; 4 2 2]A =
0 1 1 2 3 2 1 3 2 4 2 2Find the median value of each column.M = median(A)M =1.5000 2.5000 2.0000
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
21
For each column, the median value is the mean of the middle two numbers in sorted order.
std(A) It is a function of X, where X is a vector, returns the standard deviation using (1) above. The result s is the square root of an unbiased estimator of the variance of the population from which X is drawn, as long as X consists of independent, identically distributed samples.
For matrix XX = 1 5 9 7 15 22s = std(X,0,1) s = 4.2426 7.0711 9.1924s = std(X,0,2)s = 4.000 7.5056
det(A) It returns the determinant of the square matrix X.
The statement A = [1 2 3; 4 5 6;
7 8 9]
Produces
A =
1 2 3
4 5 6
7 8 9
This happens to be a singular
matrix, so det(A) produces a very
small number.
Changing A(3,3) with A(3,3) =
0 turns A into a nonsingular
matrix. Now d = det(A) produces d = 27 The
statement A = [1 2 3; 4 5 6; 7 8
9]produces
A =
1 2 3
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
22
4 5 6
7 8 9
This happens to be a singular
matrix, so det(A) produces a very
small number. Changing A(3,3)
with A(3,3) = 0 turns A into a
nonsingular matrix. Now d =
det(A) produces d = 27.
dot(a,b) It returns the scalar product of the vectors A and B. A and B must be vectors of the same length. When A and B are both column vectors, dot(A,B) is the same as A'*B.
The dot product of two vectors is calculated as shown:a = [1 2 3]; b = [4 5 6];c = dot(a,b)c = 32
cross(a,b) It returns the cross product of the vectors A and B. That is, C = A x B. A and B must be 3-element vectors. If A and B are multidimensional arrays, cross returns the cross product of A and B along the first dimension of length 3.
The cross and dot products of two vectors are calculated as shown:a = [1 2 3]; b = [4 5 6];c = cross(a,b) c = -3 6 -3d = dot(a,b)d = 32
inv(A) It returns the inverse of the square matrix X. A warning message is printed if X is badly scaled or nearly singular.
Here is an example demonstrating the difference between solving a linear system by inverting the matrix with inv(A)*b and solving it directly with A\b. A random matrix A of order 500 is constructed so that its condition number, cond(A), is 1.e10, and its norm, norm(A), is1. The exact solution x is a random vector of length 500 and the right-hand side is b = A*x. Thus the system of linear equations is badly conditioned, but consistent.On a 300 MHz, laptop computer
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
23
the statementsn = 500; Q = orth(randn(n,n));d = logspace(0,-10,n);A = Q*diag(d)*Q';x = randn(n,1);b = A*x;tic, y = inv(A)*b; tocerr = norm(y-x)res = norm(A*y-b)produceelapsed_time = 1.4320 err = 7.3260e-006 res = 4.7511e-007while the statementstic, z = A\b, tocerr = norm(z-x)res = norm(A*z-b)produceelapsed_time = 0.6410err = 7.1209e-006res = 4.4509e-015It takes almost two and one half times as long to compute the solution with y = inv(A)*b as with z = A\b. Both produce computed solutions with about the same error, 1.e-6, reflecting the condition number of the matrix. But the size of the residuals, obtained by plugging the computed solution back into the original equations, differs by several orders of magnitude. The direct solution produces residuals on the order of the machine accuracy, even though the system is badly conditioned.The behavior of this example is typical. Using A\b instead of inv(A)*b is two to three times as fast and produces residuals on
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
24
the order of machine accuracy, relative to the magnitude of the data.
7. Conclusion:I therefore conclude that Matlab can be used as an engineering devise in solving common mathematical problems such as mathematical computations, modelings, graphs, etc.
8. Further Readings: Ferraris, G. and Manenti, F. (2010). Interpolation and regression models for the chemical engineer: solving numerical problems. Germany: Wiley-VCH Verlag Filo, O. (2010). Information processing by biochemical systems: neural network type configurations. New Jersey: Wiley. Gopal, S. (2009). Bioinformatics: a computing perspective. India: McGraw-Hill Science/Engineering Math. Jaluria, Y. (2012). Computer methods for engineering with MATLAB applications (2nd ed.). Boca, Raton,Florida: CRC Press. Knopf, F. C. (2012). Modeling, analysis and optimization of process and energy systems.Hoboken, New Jersey: John Wiley and Sons. Velten, K. (2009). Mathematical modeling and simulation: introduction for scientists and engineers. Singapore: Wiley-VCH.
9. Assessment (Rubric for Laboratory Performance):TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES
RUBRIC FOR MODERN TOOL USAGE(Engineering Programs)
Student Outcome (e): Use the techniques, skills, and modern engineering tools necessary for engineering practice in complex engineering activities.Program: Chemical Engineering Course: CHE 530D1 Section: _______ ____Sem SY ________
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting
25
Performance Indicators
Unsatisfactory1
Developing2
Satisfactory3
Very Satisfactory4
Score
1. Apply appropriate techniques, skills, and modern tools to perform a discipline-specific engineering task.
Fails to identify any modern techniques to perform discipline-specific engineering task.
Identifies modern techniques but fails to apply these in performing discipline-specific engineering task.
Identifies modern techniques and is able to apply these in performing discipline-specific engineering task.
Recognizes the benefits and constraints of modern engineering tools and shows intention to apply them for engineering practice.
2. Demonstrate skills in applying different techniques and modern tools to solve engineering problems.
Fails to apply any modern tools to solve engineering problems.
Attempts to apply modern tools but has difficulties to solve engineering problems.
Shows ability to apply fundamental procedures in using modern tools when solving engineering problems.
Shows ability to apply the most appropriate and effective modern tools to solve engineering problems.
3. Recognize the benefits and constraints of modern engineering tools.
Does not recognize the benefits and constraints of modern engineering tools.
Recognizes some benefits and constraints of modern engineering tools.
Recognizes the benefits and constraints of modern engineering tools and shows intention to apply them for engineering practice.
Recognizes the need for benefits and constraints of modern engineering tools and makes good use of them for engineering practice.
Total ScoreMean Score = (Total Score / 3)
Percentage Rating = (Total Score / 12) x 100%Evaluated by: ______________________________________ _______________ Printed Name and Signature of Faculty Member Date
Bautista, Keziah Lynn S. Laboratory Exercise No. 1Familiarization with Matlab Environment, November 9, 2013Built-in Functions, Matrices and Plotting