22
PH15010 PH15010 Laboratory Techniques - Laboratory Techniques - An Introduction to MATHCAD An Introduction to MATHCAD

PH15010

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

PH15010PH15010

Laboratory Techniques -Laboratory Techniques -

An Introduction to MATHCADAn Introduction to MATHCAD

IntroductionIntroduction

• IndicesIndices• Range VariablesRange Variables• The vectorise operatorThe vectorise operator• SummationSummation• Reading data filesReading data files

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

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

Don’t confuse Text and Don’t confuse Text and array subscriptsarray subscripts

• Text SubscriptText Subscript– . key. key– Just a nameJust a name– 1 placeholder1 placeholder

• Array SubscriptArray Subscript– [ key[ key– Index into arrayIndex into array– 1 placeholder for 1 placeholder for

name + 1 name + 1 placeholder per placeholder per indexindex

M 0 M0 M0 0

If in doubt, don’t use text subscriptsIf in doubt, don’t use text subscripts

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

Reading Data Files #3Reading Data Files #3

• ExampleExample

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• Analysis of dataAnalysis of data