PH15010
-
Upload
donovan-merritt -
Category
Documents
-
view
21 -
download
0
description
Transcript of PH15010
PH15010PH15010
Laboratory Techniques -Laboratory Techniques -
An Introduction to MATHCADAn Introduction to MATHCAD
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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)
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’
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
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
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
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
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
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
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
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
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
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
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
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
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)
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
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