32
Laboratory Exercise No. 1 Familiarization with Matlab Environment, Built-in Functions, Matrices and Plotting 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 Rosario, Kharren Mae C. Laboratory Exercise No. 1 Familiarization with Matlab Environment, Built-in Functions, Matrices and Plotting June 15, 2015

Computer Application (Introduction to MATLAB)

Embed Size (px)

DESCRIPTION

Introduction to MATLABExercises

Citation preview

Laboratory Exercise No. 1

Familiarization with Matlab Environment, Built-in Functions, Matrices and Plotting

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 terms

7. 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 :

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.

6. Data and Results:

1.WindowPurpose

Command HistoryView a log of or search for the statements you entered in the Command Window, copy them, execute them, and more.

Command WindowRun MATLAB language statements.

Current Directory BrowserView files, perform file operations such as open, find files and file content, and manage and tune your files.

EditorCreate, edit, debug, and analyze M-files (files containing MATLAB language statements).

FiguresCreate, modify, view, and print figures generated with MATLAB.

Help BrowserView and search the documentation and demos for all your MathWorks products.

Variable EditorView array contents in a table format and edit the values.

Workspace BrowserView and make changes to the contents of the workspace.

2.SymbolPurpose

:Generates a sequence of numbers that you can use in creating or indexing into arrays

,A comma is used to separate the following types of elements.

{ }Construct or get the contents of cell arrays

lConstructor symbol for MATLAB character arrays

/ \Separate the elements of a path or folder string

%Indicate nonexecutable text within the body of a program

!Precedes operating system commands that you want to execute from within MATLAB

( )Used mostly for indexing into elements of an array or for specifying arguments passed to a called function. Parenthesis also control the order of operations, and can group a vector visually (such asx = (1:10)) without calling a concatenation function.

3.Mathematical ExpressionResult

>> 9.5 + 6/15

>> 11*5 4/3 * 5.63

>>(11+5)^4/3 * (7+3)^5/3

>>10^1.5

4.Built-in FunctionResult

>>sqrt(1430928237)

>>exp(143)

>>abs(-(-55.33))

>>log(110)

>>log10(1100)

>>factorial(100)

>>sind(90)

>>round(17/3+2^6)

>>rem(197,55)

>>sign(5)

5.>>x= 11.45

>>x=55-40*x

>>a = 12

>>B= 20

>>C= (a+B)^2 + (B/a)^5 * B^2

>>a=12,B=20; C= (a+B)^2 + (B/a)^5 * B^2

>>x = 1091279182;

>>E = sin(x)^1/2 + cos(x)^1/3

6.>>yr = [ 1994 1995 1996 1997]

>>yr = [ 1994; 2006; 2010; 2011; 2016]

>>k = [4:2:20]

>>m = [2:0.05;10]

>>r=[0:5]

>>b = [13:-2:5]

>>a = linspace(2,1,4)

>>b=linspace(10,20,5)

>>c=linspace(20,5)

7.>>a = [5 20 4;3 23 44;14 34 55]

>>b = [4 23 64 35 12 75 44 17 94 40 31 56 33 78 53]

>>cd = 6 ;e=4;h=3;>>Ram=[e,cd*h,cos(pi/2);h^1/3,sqrt(h*e/cd),4]

>>Z= [1:3:13;5:5:25;linspace(5,50,5)]

>>zr=zeros(2,5)

>>on=ones(4,3)

>>we=eye(3)

>>aa=[3 6 9]>>bb= aa'

>>B=[1 3 5 7; 1 2 3 4; 2 4 6 8]>>C=B

>>D=[ 2 23 3 34 4 45 5 56]>>E=D(2)

>>D(4)=55

>>D(3) + D(4)

>>D(3)^1/2 + D(4)^1/3

>>M=[1 4 7 9; 2 5 8 0; 3 6 9 2]

>>M(1,5)=11

>>M(2,3)-M(1,1)

8.>> v=[12 22 13 33 14 44 15 55 16]>>w=v(3:8)

>>Q=[2 5 7 9 1 3;11 12 13 14 15 16;25 37 74 53 22 19;1 2 3 4 5 6; 31 50 92 82 38 25]

>>R=Q(:,6)

>>S=Q(3,:)

>>T=Q(1:3,:)

>>U=Q(2:5,1:2)

>>V=5:2:25

>>A=[8:-2:2;ones(1,4);5:4:17;zeros(1,4)]

>>B=A([1,3],[2,3:4])

9.FunctionDescriptionExample

length(v)Returns the size of the longest dimension of v. If v is a vector, this is the same as its length.

size(v)Returns the size of v in separate variables m and n.

reshape(v,9,1)Returns the m-by-n matrix B whose elements are taken column-wise from A.

An error results if A does not have m*n elements.

diag(v)When v is a vector of n components, returns a square matrix X of order n+abs(k), with the elements of v on the kth diagonal. k = 0

diag(A)For matrix A, this function returns a column vector formed from the elements of the kth diagonal of A.

where: A is a matrix and v is a vector

10.>> b = Matlab Programming

>>c= My name is Kharren Rosario

>>c(7)

>>c(7:21)

>>Info=char(Student Name:,Kharren Rosario,Grade: A+)

11.>>VecA=[ 2 4 6 ]; VecB=[ 15 30 45 ];>>VecC= VecA + VecB

>>A=[12 -3 5;9 3 7];B=[1 3 5; 4 8 12];>>C= A - B

>>D= A + B

>>A=[1 2 3; 3 2 1; 2 4 6; 6 4 2];>>B=[4 9 ; 3 1 ; 5 2];>>C=A*B

>>D=B*A

>>F=[3 4; 2 1]; G=[7 1; 6 8];>>H=F*G

>>I=G*F

>>AV=[ 3 6 ];BV=[1;3;4];>>AV*BV

>>BV*AV

>>A=[2 3 5 7; 4 5 7 9; 1 2 4 6]; b=6;>>b*A

>>A*b

>>D=2*A

>>A=[5 -2 3; 2 1 7;8 3 1];>>B=inv(A)

>>A*B

>>A*A^-1

12.>>A = [4 -2 6;2 8 2;6 10 3];>>B= [8;4;0];>>X = A\B

>>Xb=inv(A)*B

>>C=[4 2 6;-2 8 10;6 2 3]

>>D=[8 4 0]

>>Xc=D/C

13.>>A=[4 2 9; 2 1 8]

>>B=[5 6 9; 7 4 0]

>>C=A.*B

>>D=A./B

>>E=B.^B

>>F=A*B

>>x=[3:7]

>>y=x.^1/2 + 4*x

>>x=[2:3:20]

>>y= (x.^3 + 5*x)\(x.^2*4 10)

>>x=[0:pi/4:pi]

>>y=cos(x)

14.FunctionDescriptionExample

mean(A)Returns the mean values of the elements along different dimensions of an array.

C=max(A)Returns the largest elements along different dimensions of an array.

(d,n)=max(A)Incorrent statement

min(A)Returns the smallest elements along different dimensions of an array.

(d,n)=min(A)Incorrect statement

sum(A)

Returns sums along different dimensions of an array.

sort(A)

Sorts the elements along different dimensions of an array, and arranges those elements in ascending order.

median(A)Returns the median values of the elements along different dimensions of an array.

std(A)The result is the square root of an unbiased estimator of the variance of the population from which A is drawn, as long as A consists of independent, identically distributed samples.

det(A)Returns the determinant of the square matrix A. If A contains only integer entries, the result d is also an integer.

dot(a,b)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.

cross(a,b)Returns the cross product of the vectors A and B.

inv(A)Returns the inverse of the square matrix A

7. Conclusion:

Matlab is, indeed, a very convenient tool in technical computations. With the mere use of variables, it can solve common problems in mathematics through arrays and matrices. It has various functions which performs different operations that aid in solving mathematical expressions or statements.

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 PHILIPPINESRUBRIC 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 ________Performance IndicatorsUnsatisfactory1Developing2Satisfactory3Very Satisfactory4Score

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 Score

Mean Score = (Total Score / 3)

Percentage Rating = (Total Score / 12) x 100%

Evaluated by: ______________________________________ _______________ Printed Name and Signature of Faculty Member Date

TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES363 P. Casal St., Quiapo, Manila

CHEP 530D1Computer Applications in Chemical Engineering

Engr. Crispulo G. MarananInstructor

Rosario, Kharren Mae C.Laboratory Exercise No. 1Familiarization with Matlab Environment, Built-in Functions, Matrices and Plotting June 15, 2015