psod lecture 2. matrices and vectors in chemical & process engineering appear in calculations...

47
PSOD PSOD Lecture 2 Lecture 2

Upload: percival-mcdaniel

Post on 02-Jan-2016

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

PSODPSOD

Lecture 2Lecture 2

Page 2: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:
Page 3: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MatricesMatrices and vectors and vectors in Chemical in Chemical & Process& Process Engineering Engineering

Appear in calculations when process is Appear in calculations when process is described by the system of equations:described by the system of equations:– Piping systemPiping system– Cascade ofCascade of

» ReactorsReactors

» Heat exchangersHeat exchangers

» Mixers Mixers

– System of System of apparatus and streams inapparatus and streams in chemical chemical plantplant

Page 4: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

concentrations give 4-elements vector concentrations give 4-elements vector cc To find solution we need system of 4 To find solution we need system of 4

equationsequations Equation parameters creates square matrixEquation parameters creates square matrix

Matrices in ChemicalMatrices in Chemical & Process & Process EngineeringEngineering

L, c1

L, cs

L, c2

L, c3

L, c4

V

V

V

V

Page 5: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

V, c

1

V, c

s

V, c

2

V, c

3

V, c

4

Matrices in ChemicalMatrices in Chemical & Process & Process EngineeringEngineering

)(reactionsourceoutputinput

kVcLcLcs 11

221 kVcLcLc

332 kVcLcLc

443 kVcLcLc

sLcccckVLc 4321 000

000 4321 ccckVLLc

000 4321 cckVLLcc

000 4321 ckVLLccc

Page 6: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

V, c

1

V, c

s

V, c

2

V, c

3

V, c

4

Matrices in ChemicalMatrices in Chemical & Process & Process EngineeringEngineering

kVLL

kVLL

kVLL

kVL

00

00

00

000

4

3

2

1

c

c

c

c

0

0

0sLc

Page 7: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD – vectors and matrixMathCAD – vectors and matrix

Page 8: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD – vectors and matrixMathCAD – vectors and matrix Matrix operationsMatrix operations

– Multiply by constantMultiply by constant– Matrix transpose [ctrl]+[1]Matrix transpose [ctrl]+[1]– Inverse [^][-][1]Inverse [^][-][1]– Matrix multiplyingMatrix multiplying– DeterminantDeterminant

Page 9: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

To read the matrix elements ATo read the matrix elements Ar, kr, k: key [[] r- : key [[] r-

row row nrnr, k – column , k – column nrnr– e.g. element Ae.g. element A1,11,1 keystrokes: [A] keystrokes: [A][[][[][1][,][1][=][1][,][1][=]

To chose matrix columnTo chose matrix column:: MM<col.nr><col.nr>

– First column A( AFirst column A( A<0><0>):):keys [A][ctrl]+[6][0]keys [A][ctrl]+[6][0]

Default first columnDefault first column&row&row number is 0, number is 0, – (to change : Math/Options/Array Or(to change : Math/Options/Array Oriigin)gin)

MathCAD – vectors and matrixMathCAD – vectors and matrix

Page 10: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD – vectors and matrixMathCAD – vectors and matrix

Calculations of dot product and cross Calculations of dot product and cross product of vectorsproduct of vectors

Page 11: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Special definition of matrix elements as a Special definition of matrix elements as a function of row-column number function of row-column number MMi,ji,j==ff((i,ji,j))

– E.g. Value of element is equal to product of E.g. Value of element is equal to product of column and row numbercolumn and row number

MathCAD – vectors and matrixMathCAD – vectors and matrix

Constrain: function arguments have to be integer

Page 12: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD 3D graphsMathCAD 3D graphs 3D graphs3D graphs of function of function on the base of matrix : on the base of matrix : [ctrl][ctrl]

+[2]+[2] [M] [M] – M – matrix defined earlierM – matrix defined earlier

Page 13: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

3D Graphs of function of real type 3D Graphs of function of real type argumentsarguments

– Using procedure: CreateMesh(function, Using procedure: CreateMesh(function, lb_v1, ub_v1, lb_v2, ub_v2lb_v1, ub_v1, lb_v2, ub_v2, v1grid, v2grid, v1grid, v2grid))

– Assign result to variableAssign result to variable– Plot of the variable Plot of the variable is is similarsimilar to to plot of plot of

matrix ([ctrl]+[2])matrix ([ctrl]+[2])

MathCAD 3D graphsMathCAD 3D graphs

Boundaries can be the real numbers. (def. –5,5)

Grids have to be integer numbers (def. 20)

Page 14: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD 3D graphsMathCAD 3D graphs

Page 15: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD 3D graphs - formatingMathCAD 3D graphs - formating

Page 16: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD 3D graphs – formatting: fill optionsMathCAD 3D graphs – formatting: fill options

Page 17: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD 3D graphs – formatting: fill optionsMathCAD 3D graphs – formatting: fill options

Contours colour filled

Page 18: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD 3D graphs – formatting: MathCAD 3D graphs – formatting: lineline options options

Page 19: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD 3D graphs – formatting: MathCAD 3D graphs – formatting: LightingLighting

Page 20: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD 3D graphs – formatting: Fog and MathCAD 3D graphs – formatting: Fog and perspectiveperspective

Page 21: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD 3D graphs – formatting: MathCAD 3D graphs – formatting: BBackplane and ackplane and Grids Grids

Page 22: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD 3DMathCAD 3D scatter scatter graphs graphs

Data given as three Data given as three vectors of each point vectors of each point coordinates coordinates – Equal vector sizeEqual vector size– Button on Graph Button on Graph

toolbar: 3D Scatter toolbar: 3D Scatter PlotPlot

– In the placeholder In the placeholder type in brackets the type in brackets the vectors names vectors names separated by comasseparated by comas

Page 23: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Predefined constantsPredefined constants

e = 2,718 – natural logarithm basee = 2,718 – natural logarithm base g = 9,81 m/sg = 9,81 m/s22 – acceleration of gravity – acceleration of gravity = 3,142 – circle perimeter/diameter ratio= 3,142 – circle perimeter/diameter ratio

Page 24: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Solving of algebraic equation Solving of algebraic equation

When equation is implicitWhen equation is implicit When we don’t want to separate variablesWhen we don’t want to separate variables

Page 25: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD equation solvMathCAD equation solversers

Single equation (one unknown value)Single equation (one unknown value)1.1. Given-Find methodGiven-Find method

» Input start point of variableInput start point of variable» Type "Given"Type "Given"» Type equation with using [Type equation with using [==]] ([ctrl]+[=]) ([ctrl]+[=])» Type Find(variable)=Type Find(variable)=

Page 26: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD MathCAD equation solvingequation solving

Given-Find – solving methods Given-Find – solving methods – Linear (function of type y=cLinear (function of type y=c00x + cx + c11) –starting ) –starting

point choice do not affects on results.point choice do not affects on results.– Nonlinear – according to nonlinear equation. Nonlinear – according to nonlinear equation.

Obtained result could depend on starting Obtained result could depend on starting point. Available methods: point. Available methods:

» Conjugate Gradient Conjugate Gradient » Quasi – NewtonQuasi – Newton» Levenberg-MarquardtLevenberg-Marquardt» Quadratic Quadratic

The choice of method is automatic by The choice of method is automatic by default. User can choose method from the default. User can choose method from the pop-up menu over word Find.pop-up menu over word Find.

Page 27: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Single equation (one unknown value)Single equation (one unknown value)2.2. Root procedure:Root procedure:

Root(function, variable, low_Root(function, variable, low_limitlimit, up_, up_limitlimit)=)=– Values of function at the bounds must have different signsValues of function at the bounds must have different signs

or

MathCAD equation solvingMathCAD equation solving

Page 28: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Single equation (one unknown value)Single equation (one unknown value)2.2. Root procedureRoot procedure

methods:methods:1.1. Secant methodSecant method2.2. Mueller method Mueller method (2(2ndnd order polynomial) order polynomial)

MathCAD equation solvingMathCAD equation solving

x3x2

y3x1

y1

y2

x4

x5

32

32224 yy

xxyxx

ii

iiiii yy

xxyxx

1

1111

Page 29: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Single equation (one unknown value)Single equation (one unknown value)3.3. Special procedure: polyroots for the Special procedure: polyroots for the

polynomialspolynomials.. Argument of procedure is a Argument of procedure is a vector of polynomial coefficients (avector of polynomial coefficients (a00, a, a11...). ...).

The result is a vector too.The result is a vector too.

MathCAD equation solvingMathCAD equation solving

Methods:1. Laguerre's method2. companion matrix

Page 30: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Laguerre's method

k

k

xp

xpG

Polynomial p(x) of degree n. Starting from assumed xk.

k

k

xp

xpGH

2

21 GnHnG

na

axx kk 1

Page 31: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

The system of linear equationsThe system of linear equations– Solving on the base of matrix Solving on the base of matrix toolbartoolbar::

» Prepare square matrix of equations coefficients Prepare square matrix of equations coefficients (A) and vector of free terms (B)(A) and vector of free terms (B)

» Do the operation x:=ADo the operation x:=A-1-1BB and show result: x= and show result: x=

OrOr

» Use the procedure LSOLVE: lsolve(A,B)=Use the procedure LSOLVE: lsolve(A,B)=

MathCAD, the system of equations solvingMathCAD, the system of equations solving

Page 32: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD, the system of equations solvingMathCAD, the system of equations solving

Page 33: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

The system of nonlinear equationThe system of nonlinear equation– Can be solved using given-find methodCan be solved using given-find method

» Assign starting values to variablesAssign starting values to variables

» Type GivenType Given

» Type the equationType the equationss using using == sign sign ((boldbold) )

» Type Find(var1, var2,...)=Type Find(var1, var2,...)=

MathCAD, the system of equations solvingMathCAD, the system of equations solving

Page 34: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD, the system of equations solvingMathCAD, the system of equations solving

Page 35: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Differential eq. Solvers in Differential eq. Solvers in MathCADMathCAD

Page 36: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Ordinary differential equations Ordinary differential equations solvingsolving

Numerical methods:Numerical methods:– Gives only values not functionGives only values not function– Engineer usually needs values Engineer usually needs values – There is no need to make complicated There is no need to make complicated

transformations (e.g. variables separation)transformations (e.g. variables separation)– Basic method implemented in MathCAD is Basic method implemented in MathCAD is

Runge-Kutta 4Runge-Kutta 4thth order method. order method.

Page 37: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Ordinary differential equations Ordinary differential equations solvingsolving

Numerical methods principleNumerical methods principle– Calculation involve bounded Calculation involve bounded rangerange of of

independent variable onlyindependent variable only– Every point is being calculated on the base of Every point is being calculated on the base of

one or few points calculated before or givenone or few points calculated before or given starting points.starting points.

– Independent variable is calculated using step:Independent variable is calculated using step:

xxi+i+11 = x = x i i + h = x + h = xii++xx– Dependent value is calculated according to the Dependent value is calculated according to the

methodmethodyyi+i+11 = = yy i i + +yy= = yy i i + +KKii

Page 38: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Ordinary differential equations Ordinary differential equations solvingsolving

Runge-Kutta 4Runge-Kutta 4thth order method principles: order method principles:– New point of the integral is calculated on the New point of the integral is calculated on the

base of one point (given/calculated earlier) and base of one point (given/calculated earlier) and 4 intermediate values 4 intermediate values

51

4321

34

23

12

1

26

1

,

2

1,

2

1

2

1,

2

1

,

hOKyy

kkkkK

kyhxhFk

kyhxhFk

kyhxhFk

yxhFk

ii

ii

ii

ii

ii

Page 39: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD differential equationsMathCAD differential equations

Single, first order differential equationSingle, first order differential equation

1.1. Assign the initial value of dependent variable Assign the initial value of dependent variable (optionally(optionally))

2.2. Define the derivative functionDefine the derivative function

3.3. Assign to the new variable the integrating function Assign to the new variable the integrating function rkfixed:rkfixed:

R:=rkfixed(init_v, low_bound, up_bound, num_seg, function)R:=rkfixed(init_v, low_bound, up_bound, num_seg, function)

),( yxfdx

dy 00 0

, yyxx xx Initial

condition

Page 40: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

4.4. Result is matrix (table) of two columns: first Result is matrix (table) of two columns: first contain independent values second dependent onescontain independent values second dependent ones

5.5. To show result as a plot: RTo show result as a plot: R<1><1>@R@R<0><0>

NN y

y

y

y

x

x

x

x

R

,1

2,1

1,1

0,1

2

1

0

......

MathCADMathCAD,, differential equations differential equations

Page 41: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD differential equationsMathCAD differential equations

Page 42: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

System of first order differential equationsSystem of first order differential equations

1.1. Assign the vector of initial conditions of dependent Assign the vector of initial conditions of dependent variables (starting vector)variables (starting vector)

2.2. Define the Define the vectorvector function of derivatives (right-hand function of derivatives (right-hand sides of equations)sides of equations)

3.3. Assign to the variable function rkfixed:Assign to the variable function rkfixed:R:=rkfixed(init_vect, low_bound, up_bound, num_seg, function)R:=rkfixed(init_vect, low_bound, up_bound, num_seg, function)

101

100

,,

,,

yyxfdx

dy

yyxfdx

dy

011

000

0

0

0

yy

yy

xx

xx

xx

MathCAD differential equationsMathCAD differential equations

Page 43: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

4.4. Result is matrix (table) of three columns: Result is matrix (table) of three columns: first contain independent values, 2first contain independent values, 2ndnd column column containscontains first dependent first dependent variable variable values, values, third second ones :third second ones :

5.5. Results as a plot: RResults as a plot: R<1><1>,R,R<2><2>@ R@ R<0><0>

NNN y

y

y

y

y

y

y

y

x

x

x

x

R

,2

2,2

1,2

0,2

,1

2,1

1,1

0,1

2

1

0

.........

MathCAD differential equationsMathCAD differential equations

Page 44: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

011

000

0

0

0

yy

yy

xx

xx

xx

MathCAD differential equationsMathCAD differential equations

Page 45: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

Single second order equationSingle second order equation

1.1. Transform the second order equation to the Transform the second order equation to the system of two first order equations:system of two first order equations:

dx

dyyxf

dx

yd,,

2

2

0

00

0

0,

ydx

dy

yyxx

xx

xx

Initial

condition

dx

dz

dx

ydz

dx

dz

dx

dyzy 1

2

2

10

0 , ,

101

10

,, zzxfdx

dz

zdx

dz

011

000

0

0

0

zz

zz

xx

xx

xx

MathCAD differential equationsMathCAD differential equations

Page 46: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD differential equationsMathCAD differential equations

Example:Example:Solve the second order differential equation Solve the second order differential equation

(calculate(calculate:: values of function values of function and itsand its first first derivatives) given by equation:derivatives) given by equation:

While While yy=10 and =10 and yy’=-1 for ’=-1 for xx=0=0In the range of In the range of xx=<0,1>=<0,1>

yyxdx

yd 322

2

Page 47: PSOD Lecture 2. Matrices and vectors in Chemical & Process Engineering Appear in calculations when process is described by the system of equations:

MathCAD differential equationsMathCAD differential equations

System of equationsStarting vector Vectoral function