220 likes | 325 Views
PH15010. Laboratory Techniques - An Introduction to MATHCAD. Introduction. Indices Range Variables The vectorise operator Summation Reading data files. Addressing Arrays with Indices. Index addressing allows access to individual elements of array Examine & Set elements
E N D
PH15010 Laboratory Techniques - An Introduction to MATHCAD
Introduction • Indices • Range Variables • The vectorise operator • Summation • Reading data files
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
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
Text Subscript . key Just a name 1 placeholder Array Subscript [ key Index into array 1 placeholder for name + 1 placeholder per index Don’t confuse Text and array subscripts If in doubt, don’t use text subscripts
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 • Analysis of data