MathCAD
DataData
Data in tables Tables are analogous to matrixTables are analogous to matrix The numbers of columns and rows can be dynamically The numbers of columns and rows can be dynamically
changedchanged (in contrast to matrix) (in contrast to matrix) To enter table:To enter table:
Menu: Insert/Menu: Insert/DataData/Table/Table 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 must contains the same number of data. If Each rows must contains the same number of data. If
data are missing the value ‘0’ will be assigneddata are missing the value ‘0’ will be assigned Access to data in table are matrix like. Access to data in table are matrix like.
Data in tables
Data in tables
Row appears Row appears in matrix in matrix when only 1 data is when only 1 data is inserted into the cell:inserted into the cell: Matrix size = specified cell in the lowest row Matrix size = specified cell in the lowest row
and in last column and in last column Unfilled cells contains 0Unfilled cells contains 0 Once specified cell can not be unspecifiedOnce specified cell can not be unspecified!!
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
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 MATLABMATLAB
To insertTo insert text text file containing data: file containing data: Menu: Menu: Insert/Insert/DataData//File InputFile Input Chose file formatChose file format Browse Browse to to the file locationthe file location In the appeared placeholder type variable name that In the appeared placeholder type variable name that
will be assigned to the contents of filewill be assigned to the contents of file
Inserting the text file
Inserting the text file Changes in the text file locationChanges in the text file location
Inserting the Excel sheets 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 embedded). Excel all Excel functions (object embedded). Excel has to be installed in system.has to be installed in system.
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 worksheet). If no data have to (relatively to Excel worksheet). If no data have to be inserted into thebe inserted into the Excel Excel worksheet type inputs worksheet type inputs number 0number 0
Type ranges corresponding to outputsType ranges corresponding to outputs – e.g. A1:B10 – e.g. A1:B10 ((ifif sheet name i sheet name iss different from Sheet1 type sheet different from Sheet1 type sheet namename – 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
MathCAD files as data source in MathCAD
MathCAD can use data included in other MathCAD MathCAD can use data included in other MathCAD filesfiles
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 file on disc or type file addressBrows file on disc or type file address Below the insertion all data, definitions, Below the insertion all data, definitions,
assignment from inserted file are valid in the assignment from inserted file are valid in the present documentpresent document
Problem: Problem: matrix/vectormatrix/vector variables. variables.
Data analysis and optimisation
ApproximationApproximation
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))
application Simplifying calculations when original Simplifying calculations when original
function function ff((xx) is defined by complicated ) is defined by complicated expression expression
Creation of continuous dependency when Creation of continuous dependency when function function ff((xx) is ascribed on discrete set of ) is ascribed on discrete set of arguments. For known form of arguments. For known form of approximating function only values of approximating function only values of function parameters giving the best function parameters giving the best approximation are to determine. approximation are to determine.
types of approximation
Interpolating approximationInterpolating approximation
Uniform approximationUniform approximation
Square-mean approximation Square-mean approximation
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
Uniform approximation
Function Function FF((xx) approximating function ) approximating function ff((xx) ) in the range [in the range [aa,,bb], that maximal residuum ], that maximal residuum reaches minimumreaches minimum
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
Condition for discreet set of arguments:Condition for discreet set of arguments:
min2
iii xfxFE
Square-mean approximation
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
Approximating algorithm:Approximating algorithm:1.1. Insert data to be approximateInsert data to be approximate2.2. Build the approximating functionBuild the approximating function3.3. Create a counting variable with values Create a counting variable with values
from 0 to number of data minus 1from 0 to number of data minus 14.4. Build function that calculates sum of Build function that calculates sum of
square of deviations with parameters of square 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.Use the function minimize.
Square-mean approximation in MathCAD
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
Other MathCAD tools for approximation
genfit
Syntax:Syntax:c:=genfit(X, Y, c0, F)c:=genfit(X, Y, c0, F) X –X – vector of vector of independent values from data set independent values from data set Y - Y - vector ofvector of dependent values from data set dependent values from data set c0 – starting vector of searched parametersc0 – starting vector of searched parameters F – vector function of independent variable and F – 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
c - vector of searched parametersc - vector of searched parameters
regress Approximation by polynomial functionApproximation by polynomial function
Syntax: Z:= Syntax: Z:= rregress(X, Y, s) egress(X, Y, s) X – vector of independent values from data X – vector of independent values from data
setset Y - vector of dependent values from data setY - vector of dependent values from data set s – polynomial degrees – polynomial degree Z – result: vectorZ – result: vector,, s+1 last elements are s+1 last elements are
parameters of polynomialparameters of polynomial (starting from x (starting from x00 parameter)parameter)
Linear, cubic, polynomial splineinterpolating approximation
Approximation by Approximation by linear (cubic etc.)linear (cubic etc.) spline spline function function Syntax: Z:=lspline(X, Y)Syntax: Z:=lspline(X, Y) (cspline, pspline)(cspline, pspline)
X – vector of independent values from data setX – vector of independent values from data set Y - vector of dependent values from data setY - vector of dependent values from data set Data in set has to be sorted! Manually or by use Data in set has to be sorted! Manually or by use
function csort: W:=csort(W,i), W – matrix of function csort: W:=csort(W,i), W – matrix of data, i – nr of ordering columndata, i – nr of ordering column
Z – result: vector of parameters of cubic spline Z – result: vector of parameters of cubic spline functionfunction
Can be derivate
Can be integrate
Interpreting function Operates on vectors obtained from regress and Operates on vectors obtained from regress and
ll(c,p)(c,p)spline functionsspline functions BBuilding the continuousuilding the continuous approximating function on approximating function on
the base of determined parametersthe base of determined parameters Syntax: F(x):=interp(Z, X, Y, x) Syntax: F(x):=interp(Z, X, Y, x)
Z – vector given by approximating functionZ – vector given by approximating function X – vector of independent values from data setX – vector of independent values from data set Y - vector of dependent values from data setY - vector of dependent values from data set x – independent valuesx – independent values
Interpreting function is implicit but can be derivateInterpreting function is implicit but can be derivatedd and integrateand integratedd