39
PSOD PSOD Lecture 2 Lecture 2

PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

Embed Size (px)

Citation preview

Page 1: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

PSODPSOD

Lecture 2Lecture 2

Page 2: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]
Page 3: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

MathCAD – vectors and matrixMathCAD – vectors and matrix

Page 4: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 5: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 keys: [A] keys: [A][[][[][1][,][1][=][1][,][1][=]

To chose matrix column To chose matrix column – First column A( AFirst column A( A<0><0>):):

keys [A][ctrl]+[6][0]keys [A][ctrl]+[6][0]– Default first column number is 0, (to change : Default first column number is 0, (to change :

Math/Options/Array OrMath/Options/Array Oriigin)gin)

MathCAD – vectors and matrixMathCAD – vectors and matrix

Page 6: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 7: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 8: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 9: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 similarlyPlot of the variable similarly to to plot of plot of

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

MathCAD 3D graphsMathCAD 3D graphs

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

Grids have to be integer type numbers (def. 20)

Page 10: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

MathCAD 3D graphsMathCAD 3D graphs

Page 11: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

MathCAD 3D graphs - formatingMathCAD 3D graphs - formating

Page 12: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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

Page 13: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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

Contours colour filled

Page 14: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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

Page 15: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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

Page 16: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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

Page 17: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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

Page 18: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 19: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

MathCAD equation solvingMathCAD equation solving

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 20: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

MathCAD MathCAD equation solvingequation solving

Given-Find – solving methods Given-Find – solving methods – Linear (function of type cLinear (function of type c00xx00 + c + c11xx11 +...+ c +...+ cnnxxnn) –) –

starting point do not affects on results, it only defines starting point do not affects on results, it only defines size of matrix/vector of the solution.size of matrix/vector of the solution.

– Nonlinear – according to nonlinear equation. Nonlinear – according to nonlinear equation. Obtained result could depend on startingObtained result could depend on starting point point. . Available methods: Available methods:

» Conjugate Gradient Conjugate Gradient

» Quasi – NewtonQuasi – Newton

» Levenberg-MarquardtLevenberg-Marquardt

» Quadratic Quadratic

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

Page 21: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 22: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 23: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 24: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 25: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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

Page 26: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 27: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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

Page 28: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 29: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 30: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 31: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 32: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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

......

MathCAD differential equationsMathCAD differential equations

Page 33: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

MathCAD differential equationsMathCAD differential equations

Page 34: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 35: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 first first dependent values, third second ones :dependent values, 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 36: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

011

000

0

0

0

yy

yy

xx

xx

xx

MathCAD differential equationsMathCAD differential equations

Page 37: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 38: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

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 39: PSOD Lecture 2. MathCAD – vectors and matrix Matrix operations Matrix operations –Multiply by constant –Matrix transpose [ctrl]+[1] –Inverse [^][-][1]

MathCAD differential equationsMathCAD differential equations

System of equationsStarting vector Vectoral function