370 likes | 498 Views
PH15010. Laboratory Techniques - An Introduction to MATHCAD. Introduction. Review of last week Vector and Matrix Maths Statistics Solving simultaneous equations with matrices. Review of Last Week. Processing experimental data with arrays Adding Error bars to graphs Pre-Processing Data
E N D
PH15010 Laboratory Techniques - An Introduction to MATHCAD
Introduction • Review of last week • Vector and Matrix Maths • Statistics • Solving simultaneous equations with matrices
Review of Last Week • Processing experimental data with arrays • Adding Error bars to graphs • Pre-Processing Data • Convert l to f • Logarithms for power law • Extract slope & intercept from data
Functions Reviewed • Take one or more inputs (parameters) and return a value or values • From f(x) toolbar if you don’t know the name • Afunction(parameters)= • Avariable:=Afunction(p1,p2,p3…) • Use the help system/f(x) dialog
Matrix & Vector Maths • Used for: • Processing experimental data • Statistics • Resolving forces etc in 2D, 3D • Co-ordinate transformations • Simultaneous Equations • Applying transforms to data
Creating Arrays in MathCAD • 2 ways of entering arrays • Input Table (already encountered) • Spreadsheet type entry • Expand to fit data available • Insert Matrix Dialog box • Array of placeholders • Good if you know how many elements in matrix/vector
Creating an array with Insert|Matrix… • Same for defining ordinary variable • Follow : with • [:::] from toolbar • <ctrl-m> • Insert|Matrix • Dialog box for rows & columns
Empty 3 – element vector Placeholders to fill in Can use units Creating arrays with Insert|Matrix…
Matrix Maths #2(Symbolically) • Matrix Multiplication • Determinant • Addition of constant
Matrix & Vector Maths • Add, Multiply & Divide matrices/vectors • Must have correct numbers of rows & columns
Addressing Arrays with Indices • Index addressing allows access to individual elements of array • Examine & Set elements • Indices start at 0 • Indices use [ key • 2D matrices use two indices for row, column selection
Indices #1 Vector Example • Simple 2 element vector • Examine elements • Set element 0 • Result of setting
Indices #2Matrix Example • Sample matrix • Examine elements • Subscript too big • Set element • Result
Accessing Parts Of Arrays • Index addressing – single element • Column Extract operator M<> • Submatrix() function • Transposing matrices
Matrix to operate on Rows Columns The submatrix() function Define a matrix Use submatrix() to extract part of the array
Transpose Rows & Columns • Uses MT operator • From matrix toolbar
Other matrix functions1. Information • Return information about: • Size of matrix • rows(M), cols(M), last(V), length(V) • Contents of matrix • min(A), max(A) • V
Other matrix functions2. Manipulation • Create new arrays • Put 2 arrays together • stack(A1,A2) • augment(A1,A2) • Sorting • sort(V), reverse(A) • rsort(M,r), csort(M,c)
Statistical Functionson Vectors #1 • From f(x) dialog box under “Statistics” • Averaging • mean() ‘Average value’ • median() ‘Half way item’ • mode() ‘Most common value’
Statistical Functionson Vectors #2 • Variance & Standard Deviation • 2 forms of each • Analysis of sample • Stdev(), Var() • Analysis of whole population • stdev(), var() • Note capitalisation
Vectorise Operator #1 • From matrix toolbar • Forces evaluation on element by element basis • Overrides normal matrix maths • ‘dot’ product • Determinant |M| • Powers Mx
Dot product With vectorise operator Vectorise Operator #2
Range Variables • Take on a series of values • Define using semicolon [;]
Range Variables #2 • Restrictions on where used • ‘illegal context’ error message • Useful for filling arrays
Filling Arrays using RVs • Define RV • Use RV in array index & expression
Processing Arrays using RVs • Use RV in expressions to create output array from input array
Range Variables with different step sizes • Can create RVs with different step sizes. • Enter first 2 values separated by comma [,] before typing [;]
Summation #1 • Summation operator on matrix palette • Sum of all elements in a vector
Summation #2 • Operators on Calculus palette • Do summation on any expression • 2 forms • Plain => defines local RV • Range Variable => uses existing RV
Sum of first 5 integers Sum of elements 20-30 of vector Counts Summation #3
2 terms 4 terms 9 terms Summation #4Reciprocals of factorials
Data Files • Used Input table to put data into MathCAD by hand. • Can use Import on input table to get from a file (makes a copy) • Select table & right-click • Also can link to data file with File Read Component (preferred)
Reading Data Files #1 • File Read Component • Reads from datafile array • Text files • Numbers separated by comma or tab • Other formats supported
Reading Data Files #2 • Insert|Component…|File Read or Write • Wizard: • (Select file type) • Browse for file • Finish • Give name for array
Reading Data Files #3 • Example
This weeks worksheet • Arrays & Indices • Columns (Revision) • Submatrix() function • Other array functions • Reading data from file