![Page 1: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/1.jpg)
PH15010PH15010
Laboratory Techniques -Laboratory Techniques -
An Introduction to MATHCADAn Introduction to MATHCAD
![Page 2: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/2.jpg)
IntroductionIntroduction
• Review of last weekReview of last week• Vector and Matrix MathsVector and Matrix Maths• StatisticsStatistics• Solving simultaneous equations Solving simultaneous equations
with matriceswith matrices
![Page 3: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/3.jpg)
Review of Last WeekReview of Last Week
• Processing experimental data with Processing experimental data with arraysarrays
• Adding Error bars to graphsAdding Error bars to graphs• Pre-Processing DataPre-Processing Data
– Convert Convert to f to f– Logarithms for power lawLogarithms for power law
• Extract slope & intercept from dataExtract slope & intercept from data
![Page 4: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/4.jpg)
Functions ReviewedFunctions Reviewed
• Take one or more inputs Take one or more inputs (parameters) and return a value or (parameters) and return a value or valuesvalues
• From f(x) toolbar if you don’t know From f(x) toolbar if you don’t know the namethe name
• Afunction(parameters)=Afunction(parameters)=• Avariable:=Afunction(p1,p2,p3…)Avariable:=Afunction(p1,p2,p3…)• Use the help system/f(x) dialogUse the help system/f(x) dialog
![Page 5: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/5.jpg)
Matrix & Vector MathsMatrix & Vector Maths
• Used for:Used for:– Processing experimental dataProcessing experimental data– StatisticsStatistics– Resolving forces etc in 2D, 3DResolving forces etc in 2D, 3D– Co-ordinate transformationsCo-ordinate transformations– Simultaneous EquationsSimultaneous Equations– Applying transforms to dataApplying transforms to data
![Page 6: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/6.jpg)
Creating Arrays in Creating Arrays in MathCADMathCAD
• 2 ways of entering arrays2 ways of entering arrays– Input Table (already encountered)Input Table (already encountered)
• Spreadsheet type entrySpreadsheet type entry• Expand to fit data availableExpand to fit data available
– Insert Matrix Dialog boxInsert Matrix Dialog box• Array of placeholdersArray of placeholders• Good if you know how many elements in Good if you know how many elements in
matrix/vectormatrix/vector
![Page 7: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/7.jpg)
Creating an array with Creating an array with Insert|Matrix…Insert|Matrix…
• Same for defining ordinary variable Same for defining ordinary variable • Follow : withFollow : with
– [:::] from toolbar[:::] from toolbar– <ctrl-m><ctrl-m>– Insert|MatrixInsert|Matrix
• Dialog box for rows & columnsDialog box for rows & columns
![Page 8: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/8.jpg)
Creating arrays with Creating arrays with Insert|Matrix…Insert|Matrix…
Placeholders to fill inPlaceholders to fill inMyVector
1
2
3
Can use unitsCan use unitsMyVector
1
2
3
mm
MyVector Empty 3 – element Empty 3 – element
vector vector
![Page 9: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/9.jpg)
Matrix Maths #1Matrix Maths #1
VA 12
3 MA 1
2
4
3
5 Addition of constant
VA 33
6 MA 3
3
9
6
12 Multiplication by scalar
VA VB 11 Dot product of 2 vectors
Dot product of 2 matricesMA MB
19
43
22
50
MA VA5
11 Dot product of matrix and vector
![Page 10: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/10.jpg)
Matrix Maths #2Matrix Maths #2(Symbolically)(Symbolically)
• Matrix Matrix MultiplicationMultiplication
• DeterminantDeterminant
• Addition of Addition of constantconstant
a
c
b
d
x
y
a x b y
c x d y
a
c
b
da d b c
a
c
b
dK
a K
c K
b K
d K
![Page 11: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/11.jpg)
Matrix & Vector MathsMatrix & Vector Maths
• Add, Multiply & Divide Add, Multiply & Divide matrices/vectorsmatrices/vectors
• Must have correct numbers of rows Must have correct numbers of rows & columns& columns
![Page 12: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/12.jpg)
Addressing Arrays with Addressing Arrays with IndicesIndices
• Index addressing allows access to Index addressing allows access to individual elements of arrayindividual elements of array
• Examine & Set elementsExamine & Set elements• Indices start at 0Indices start at 0• Indices use [ keyIndices use [ key• 2D matrices use two indices for 2D matrices use two indices for
row, column selectionrow, column selection
![Page 13: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/13.jpg)
Indices #1 Indices #1 Vector ExampleVector Example
• Simple 2 element Simple 2 element vectorvector
• Examine elementsExamine elements
• Set element 0Set element 0• Result of settingResult of setting
VA12
666
VA0 12 VA1 666
VA0 42
VA42
666
![Page 14: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/14.jpg)
Indices #2Indices #2Matrix ExampleMatrix Example
• Sample matrixSample matrix• Examine elementsExamine elements• Subscript too bigSubscript too big• Set elementSet element• ResultResult
MA1
999
2
42
3
666
MA0 0 1 MA0 1 2 MA0 2 3
MA0 3 MAMA
MA1 0 27
MA1
27
2
42
3
666
![Page 15: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/15.jpg)
Accessing Parts Of ArraysAccessing Parts Of Arrays
• Index addressing – single element Index addressing – single element
• Column Extract operator MColumn Extract operator M<> <> • Submatrix() functionSubmatrix() function• Transposing matricesTransposing matrices
![Page 16: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/16.jpg)
The submatrix() functionThe submatrix() function
MyMatrix
1
2
3
4
1
4
9
16
1
8
27
64
submatrix MyMatrix 0 2 1 2( )
1
4
9
1
8
27
Define a matrixDefine a matrix
Use submatrix() Use submatrix() to extract partto extract partof the arrayof the array
Matrix to operate onMatrix to operate on
RowsRows
ColumnsColumns
![Page 17: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/17.jpg)
Transpose Rows & Transpose Rows & ColumnsColumns
• Uses MUses MTT operatoroperator
• From matrix From matrix toolbartoolbar
MyMatrixT
1
1
1
2
4
8
3
9
27
4
16
64
MyMatrix
1
2
3
4
1
4
9
16
1
8
27
64
![Page 18: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/18.jpg)
Other matrix functionsOther matrix functions1. Information1. Information
• Return information about:Return information about:– Size of matrixSize of matrix
• rows(M), cols(M), last(V), length(V)rows(M), cols(M), last(V), length(V)
– Contents of matrixContents of matrix• min(A), max(A)min(A), max(A)VV
![Page 19: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/19.jpg)
Other matrix functionsOther matrix functions2. Manipulation2. Manipulation
• Create new arraysCreate new arrays– Put 2 arrays togetherPut 2 arrays together
• stack(A1,A2)stack(A1,A2)• augment(A1,A2)augment(A1,A2)
– SortingSorting• sort(V), reverse(A)sort(V), reverse(A)• rsort(M,r), csort(M,c)rsort(M,r), csort(M,c)
![Page 20: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/20.jpg)
Statistical FunctionsStatistical Functionson Vectors #1on Vectors #1
• From From f(x)f(x) dialog box under dialog box under “Statistics”“Statistics”
• AveragingAveraging– mean() ‘Average value’mean() ‘Average value’– median() ‘Half way item’median() ‘Half way item’– mode() ‘Most common value’mode() ‘Most common value’
![Page 21: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/21.jpg)
Statistical FunctionsStatistical Functionson Vectors #2on Vectors #2
• Variance & Standard DeviationVariance & Standard Deviation• 2 forms of each2 forms of each• Analysis of sampleAnalysis of sample
– Stdev(), Var()Stdev(), Var()
• Analysis of whole populationAnalysis of whole population– stdev(), var()stdev(), var()
• Note capitalisationNote capitalisation
![Page 22: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/22.jpg)
Vectorise Operator #1Vectorise Operator #1
• From matrix toolbar From matrix toolbar • Forces evaluation on element by Forces evaluation on element by
element basiselement basis• Overrides normal matrix mathsOverrides normal matrix maths
– ‘‘dot’ productdot’ product– Determinant |M|Determinant |M|– Powers MPowers Mxx
)(xf
)(xf
![Page 23: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/23.jpg)
Vectorise Operator #2Vectorise Operator #2
• Dot productDot product
• With vectorise With vectorise operatoroperator
1
2
3
4
5
6
32
1 4 2 5 3 6 32
1
2
3
4
5
6
4
10
18
![Page 24: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/24.jpg)
Range VariablesRange Variables
• Take on a series of valuesTake on a series of values• Define using semicolon Define using semicolon [;][;]
i 0 10
Start 5 Finish 15
i Start Finish
![Page 25: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/25.jpg)
Range Variables #2Range Variables #2
• Restrictions on where usedRestrictions on where used• ‘‘illegal context’ error messageillegal context’ error message• Useful for filling arraysUseful for filling arrays
![Page 26: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/26.jpg)
Filling Arrays using RVsFilling Arrays using RVs
• Define RVDefine RV• Use RV in array index & expressionUse RV in array index & expression
i 0 3
timei i 10 min
time
0
600
1.2 103
1.8 103
s change the units to give: time
0
10
20
30
min
![Page 27: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/27.jpg)
Processing Arrays using Processing Arrays using RVsRVs
• Use RV in expressions to create Use RV in expressions to create output array from input arrayoutput array from input array
![Page 28: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/28.jpg)
Range Variables with Range Variables with different step sizesdifferent step sizes
• Can create RVs with different step Can create RVs with different step sizes.sizes.
• Enter first 2 values separated by Enter first 2 values separated by comma comma [,][,] before typing before typing [;][;]
RV First Second Last
![Page 29: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/29.jpg)
Summation #1Summation #1
• Summation operator on matrix Summation operator on matrix palettepalette
• Sum of all elements in a vectorSum of all elements in a vector
V
![Page 30: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/30.jpg)
Summation #2Summation #2
• Operators on Calculus paletteOperators on Calculus palette• Do summation on Do summation on anyany expression expression• 2 forms2 forms
– Plain => defines local RVPlain => defines local RV– Range Variable => uses existing RVRange Variable => uses existing RV
m
ln
Expression n
Expression
![Page 31: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/31.jpg)
Summation #3Summation #3
• Sum of first 5 Sum of first 5 integersintegers
• Sum of elements Sum of elements 20-30 of vector 20-30 of vector CountsCounts
1
5
i
i
=
15
20
30
i
Countsi=
9
![Page 32: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/32.jpg)
Summation #4Summation #4Reciprocals of factorialsReciprocals of factorials
• 2 terms2 terms
• 4 terms4 terms
• 9 terms9 terms
0
8
i
1
i =
2.718
0
3
i
1
i =
2.667
0
1
i
1
i =
2
![Page 33: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/33.jpg)
Data FilesData Files
• Used Input table to put data into Used Input table to put data into MathCAD by hand.MathCAD by hand.
• Can use Import on input table to Can use Import on input table to get from a file (makes a copy)get from a file (makes a copy)– Select table & right-clickSelect table & right-click
• Also can link to data file with File Also can link to data file with File Read Component (preferred)Read Component (preferred)
![Page 34: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/34.jpg)
Reading Data Files #1Reading Data Files #1
• File Read ComponentFile Read Component• Reads from datafile Reads from datafile array array• Text filesText files
– Numbers separated by comma or tabNumbers separated by comma or tab
• Other formats supportedOther formats supported
![Page 35: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/35.jpg)
Reading Data Files #2Reading Data Files #2
• Insert|Component…|File Read or Insert|Component…|File Read or WriteWrite
• Wizard:Wizard:– (Select file type)(Select file type)– Browse for fileBrowse for file– FinishFinish
• Give name for arrayGive name for array
![Page 36: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/36.jpg)
Reading Data Files #3Reading Data Files #3
• ExampleExample
![Page 37: PH15010 Laboratory Techniques - An Introduction to MATHCAD](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649efa5503460f94c0c5b7/html5/thumbnails/37.jpg)
This weeks worksheetThis weeks worksheet
• Arrays & IndicesArrays & Indices• Columns (Revision)Columns (Revision)• Submatrix() functionSubmatrix() function• Other array functionsOther array functions• Reading data from fileReading data from file