data processing in mathcad. data in tables tables are analogous to matrices tables are analogous to...

37
Data processing in MathCAD

Upload: cecily-wiggins

Post on 25-Dec-2015

229 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Data processing in MathCAD

Page 2: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Data in tables Tables are analogous to matricesTables are analogous to matrices The numbers of columns and rows can be dynamically The numbers of columns and rows can be dynamically

changed (in contrast to matrix)changed (in contrast to matrix) To enter table:To enter table:

Menu: Insert/Data/Table (MC v. 15)Menu: Insert/Data/Table (MC v. 15) In placeholder type variable name which will be In placeholder type variable name which will be

assigned to tableassigned to table In cells type the valuesIn cells type the values Each rows and columns must contains the same Each rows and columns must contains the same

number of data. If data are missing the value ‘0’ will number of data. If data are missing the value ‘0’ will be assignedbe assigned

Access to data in table is similar to the one in matrix Access to data in table is similar to the one in matrix case. case.

Page 3: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Data in tables

Page 4: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Data in tables RowRow/column/column appears appears in table in table when only 1 data is when only 1 data is

inserted into the cell:inserted into the cell: tabletable size = specified cell in the lowest row and size = specified cell in the lowest row and

in last column in last column Unfilled cells contains 0Unfilled cells contains 0 Once specified cell can not be removedOnce specified cell can not be removed!!

To overcome problem: create new matrix To overcome problem: create new matrix with correct number of rows with correct number of rows ii and columns and columns jj usingusing

jiji ,, OLDNEW

Page 5: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

External data sources: Data in files

The most popular file formats accepted by MathCAD:The most popular file formats accepted by MathCAD: Text filesText files Excel worksheetsExcel worksheets

To insert text file containing data: To insert text file containing data: Menu: Insert/Data/File InputMenu: Insert/Data/File Input Chose file formatChose file format Browse to the file locationBrowse to the file location

path could be relative or absolutepath could be relative or absolute In the placeholder type variable name that will be In the placeholder type variable name that will be

assigned to the contents of fileassigned to the contents of file

Page 6: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Inserting the text file

Page 7: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Inserting the text file Changes in the text file locationChanges in the text file location

Page 8: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Inserting the Excel worksheets A range of Excel cells can be inserted into the A range of Excel cells can be inserted into the

MathCADMathCAD There can be more then one range in single There can be more then one range in single

insertioninsertion One variable is being assigned to one rangeOne variable is being assigned to one range All variables forms a vectorAll variables forms a vector Cells can contain numbers as well as text (in Cells can contain numbers as well as text (in

contrast to table and text filescontrast to table and text files, ver. 2001, ver. 2001)) Worksheets can be edited (double-click) using Worksheets can be edited (double-click) using

all Excel functions (object embeddedall Excel functions (object embedded - -Excel Excel has to be installed in systemhas to be installed in system))..

Page 9: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Inserting the Excel sheets

To insert worksheet:To insert worksheet: Menu: Insert/Component/ExcelMenu: Insert/Component/Excel Browse file or create newBrowse file or create new Choose number of ranges for input and output Choose number of ranges for input and output

((relatively to Excel worksheetrelatively to Excel worksheet). If no data have to ). If no data have to be inserted into thebe inserted into the Excel Excel worksheet worksheet fillfill inputs inputs numbernumber by by 0 0

Type ranges corresponding to outputsType ranges corresponding to outputs – e.g. A1:B10 – e.g. A1:B10 ((ifif workworksheet name isheet name iss different from Sheet1 type different from Sheet1 type sheet namesheet name – e.g. Sheet4!A1:B10 – e.g. Sheet4!A1:B10))

In placeholder(s) type variable(s) In placeholder(s) type variable(s) Number of outputs/inputs and range of cells can be Number of outputs/inputs and range of cells can be

edited in properties of insertionedited in properties of insertion

Page 10: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically
Page 11: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

MathCAD files as data source in MathCAD Main Main MathCAD MathCAD document document can use data included in can use data included in

other MathCAD other MathCAD documentsdocuments Access to data is possible after embedding MathCAD Access to data is possible after embedding MathCAD

file:file: menu: Insert/References, menu: Insert/References, Brows Brows the the filefile Below the insertion Below the insertion point point all data, definitions from all data, definitions from

inserted file are valid in the inserted file are valid in the mainmain document but document but worksheet options from main document overwrite worksheet options from main document overwrite options in inserted documentoptions in inserted document

Problem: matrix/vector elements numbers when Problem: matrix/vector elements numbers when array origin is different in main and inserted doc. array origin is different in main and inserted doc.

Page 12: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically
Page 13: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Data analysis and optimisation

ApproximationApproximation

Page 14: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

definition

Approximation is a part of numerical Approximation is a part of numerical analysis. It is concerned with how functions analysis. It is concerned with how functions ff((xx) can be best approximated ) can be best approximated ((fittedfitted) ) with with another functions another functions FF((xx))

Page 15: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

application Simplifying calculations when original Simplifying calculations when original

function function ff((xx) is defined by complicated ) is defined by complicated expression expression

designdesign of continuous dependency when of continuous dependency when function function ff((xx) is ) is describeddescribed on discrete set of on discrete set of arguments. arguments. If the form of approximating If the form of approximating function is given only values of function function is given only values of function parameters showing the best approximation parameters showing the best approximation have to behave to be determine. determine.

Page 16: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

types of approximation

Interpolating approximationInterpolating approximation

Uniform approximationUniform approximation

Square-mean approximation Square-mean approximation

Page 17: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Interpolating approximation NeedNeedss to satisfy condition: function given to satisfy condition: function given

ff((xx) and approximating function ) and approximating function FF((xx) have ) have the same values on the set of nodes and the same values on the set of nodes and (sometimes) the same values of derivatives (sometimes) the same values of derivatives ((if givenif given)) too. too.

1 1.5 2 2.5 3 3.5 410

20

30

40

50

60

7069

12

f a( )

z

41 a x

Page 18: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Uniform approximation

Function Function FF((xx) approximating function ) approximating function ff((xx) ) in the range [in the range [aa,,bb], satisfying condition], satisfying condition:: maximal residuum maximal residuum is set tois set to minimum minimum

Page 19: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Square-mean approximation

Approximating function is determined by Approximating function is determined by the use of condition:the use of condition:

Geometrically condition means: The area Geometrically condition means: The area between curves representing functions have between curves representing functions have to reach minimum. to reach minimum.

min2 dxxfxFEb

a

Page 20: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Condition for discreet set of arguments:Condition for discreet set of arguments:

min2

iii xfxFE

Square-mean approximation

Page 21: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Function:Function:

minimize(minimize(functionfunction, , pp1, 1, pp2,...)2,...)

can be used to determine parameters of can be used to determine parameters of approximating function minimizing the sum of approximating function minimizing the sum of square deviations between values given in the square deviations between values given in the table and calculated from the function.table and calculated from the function. functionfunction calculates the sum of square calculates the sum of square

deviations as a function of parameters.deviations as a function of parameters. pp1, 1, pp2 – parameters of approximating function2 – parameters of approximating function

Square-mean approximation in MathCAD

Page 22: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Approximating algorithm:Approximating algorithm:1.1. Insert data to be approximatedInsert data to be approximated2.2. Build the approximating functionBuild the approximating function3.3. Create a counting variable with values from 0 Create a counting variable with values from 0

to number of data minus 1to number of data minus 14.4. Build function Build function EE that calculates sum of square that calculates sum of square

of deviations with parameters of of deviations with parameters of approximating function as variablesapproximating function as variables

5.5. Assign starting values of parametersAssign starting values of parameters6.6. Use the function minimize to minimize the Use the function minimize to minimize the EE

function (deviations).function (deviations).

Square-mean approximation in MathCAD

Page 23: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically
Page 24: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Advantageous of Advantageous of minimizeminimize function: function: simplesimple explicitexplicit suitable for any approximating functionsuitable for any approximating function ccan be used in optimisation problem an be used in optimisation problem

solvingsolving

Page 25: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Other MathCAD tools for approximation

Page 26: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

genfit

Syntax:Syntax:cc:=genfit(:=genfit(X, YX, Y, , cc0, 0, FF)) XX – – vector of vector of independent values from data set independent values from data set YY - - vector ofvector of dependent values from data set dependent values from data set cc0 – starting vector of searched parameters0 – starting vector of searched parameters F F – vector function of independent variable and – vector function of independent variable and

vector c, consists of approximating function and its vector c, consists of approximating function and its derivatives on parametersderivatives on parameters

cc - vector of searched parameters - vector of searched parameters

Page 27: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically
Page 28: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

regress Approximation by polynomial functionApproximation by polynomial function

Syntax: Syntax: ZZ:= regress(:= regress(X, Y, sX, Y, s) ) XX – vector of independent values from data – vector of independent values from data

setset YY - vector of dependent values from data set - vector of dependent values from data set ss – polynomial degree – polynomial degree ZZ – result: vector, – result: vector, ss+1 last elements are +1 last elements are

parameters of polynomial (starting from parameters of polynomial (starting from xx00 parameter)parameter)

Page 29: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically
Page 30: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Linear, cubic, polynomial - splineinterpolating approximation

Approximation by Approximation by linear (cubic etc.)linear (cubic etc.) spline spline function function Syntax: Syntax: ZZ:=lspline(:=lspline(X, YX, Y)) (cspline, pspline)(cspline, pspline)

XX – vector of independent values from data set – vector of independent values from data set YY - vector of dependent values from data set - vector of dependent values from data set Data in set has to be sorted! Manually or by useData in set has to be sorted! Manually or by use

of of function csort: function csort: WW:=csort(:=csort(W,iW,i), ), WW – matrix of – matrix of data, data, ii – nr of ordering column – nr of ordering column

ZZ – result: vector of parameters of cubic spline – result: vector of parameters of cubic spline functionfunction

Page 31: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Can be derivate

Can be integrate

Page 32: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Interpreting function Operates on vectors obtained from regress and spline Operates on vectors obtained from regress and spline

family functionsfamily functions Building the continuous approximating function on Building the continuous approximating function on

the base of determined parametersthe base of determined parameters Syntax: Syntax: FF((xx):=interp():=interp(Z, X, Y, xZ, X, Y, x) )

ZZ – vector given by approximating function – vector given by approximating function XX – vector of independent values from data set – vector of independent values from data set YY - vector of dependent values from data set - vector of dependent values from data set xx – independent – independent variable (local)variable (local)

Interpreting function is implicit but can be derivateInterpreting function is implicit but can be derivatedd and integrateand integratedd

Page 33: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically
Page 34: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

MathCAD

The animationThe animation

Page 35: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Animation

EnhanceEnhancess understanding of numerical understanding of numerical outputoutput

Animations shows time dependences in real Animations shows time dependences in real time, time, as well as speeded upas well as speeded up or slowed or slowed down.down.

Make impression on viewersMake impression on viewers

Page 36: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Animation

Base of animation is variable called:Base of animation is variable called:

FRAMEFRAME Built inBuilt in, , integer typeinteger type Definition only in dialog box of animationDefinition only in dialog box of animation Parameters are: Parameters are:

starting valuestarting valueending valueending valueframe rate (frames per seconds)frame rate (frames per seconds)

Page 37: Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically

Creating animation Solve a problem Solve a problem (e.g. (e.g. create functioncreate function)) Assign counting variable to FRAMEAssign counting variable to FRAME Define a variable representing each state of solution Define a variable representing each state of solution

assigned to counting variableassigned to counting variable Create plot to animateCreate plot to animate Select plot areaSelect plot area DDisplay animate dialog box and isplay animate dialog box and sselect plot elect plot Define FRAME variable parametersDefine FRAME variable parameters Choose format of compression for animation Choose format of compression for animation

recording.recording. Press Animate button. Press Animate button.