ph24010 data handling and statistics use of mathcad to handle statistical data data storage in...

24
PH24010 Data Handling and Statistics • Use of MathCAD to handle statistical data • Data storage in vectors and matrices • MathCAD’s built-in functions: – Mean, standard deviation etc – Probability distributions • Extending MathCAD through defining functions and programming • Revision of PH1570

Upload: antony-carter

Post on 13-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

PH24010Data Handling and Statistics

• Use of MathCAD to handle statistical data• Data storage in vectors and matrices• MathCAD’s built-in functions:

– Mean, standard deviation etc– Probability distributions

• Extending MathCAD through defining functions and programming

• Revision of PH1570

Arrays, Matrices & Vectors

• Way of storing related data– Experimental Results (datasets)– Coefficients

• One variable name, many data points

• Indexing– var0, var1, var2, var3 …

Arrays, Vectors & Matrices - Terminology

• Vector – 1-dimensional

• Matrix – 2-dimensional

• Array – general term, covers both

MathCAD and arrays• Matrix toolbar has tools to:

– Create and– Operate on matrices

• Many functions f(x) operate on matrices

Creating an array• Same for defining ordinary variable

• Follow : with– [:::] from toolbar or– <ctrl-m> or– Insert|Matrix

• Dialog box for rows & columns

Creating arrays

• 3 –element vector – empty

• Placeholders to fill in

• Can use units

MyVector

MyVector

1

2

3

MyVector

1

2

3

m

s

Data Tables

• Define array and input data in one operation

• Re-sizes to fit data

• From Insert|Data|Table

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

VA12

666

VA0 12 VA1 666

VA0 42

VA42

666

Indices #2Matrix Example

• Sample matrix• Examine elements• Subscript too big• Set element• Result

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

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

Summation #1• Summation operator on matrix palette

• Sum of all elements in a vector

V

Summation #2• Operators on Calculus palette• Do summation on any expression• 2 forms

– Plain => defines local RV

– Range Variable => uses existing RV

m

ln

Expression n

Expression

Summation #3

• Sum of first 5 integers

• Sum of elements 20-30 of vector Counts

1

5

i

i

=

15

20

30

i

Countsi=

9

Writing Programs in MathCAD

• Can do much without programming

• Some algorithms need programs– Iterative, repeat until solution

• Can make other tasks simpler

• Hide detail inside a program

The Golden Rule of Programming

• Applies to all programming

• K.I.S.S. principle– Keep– It– Simple– Stupid

A MathCAD program• All MathCAD programs are functions

• Expression over multiple lines

• Lines executed in order

• Local Variables

• Value of last line is result

A simple MathCAD program #1

fExamplea b( )cos a

2b

2 2 a

2b

2a

2b

2

• Common subexpression calculated 3 times in function

Can re-write using a program

fExample(a,b) as a 2 line program

fExamplea b( ) r a2

b2

cos r( )

2 rr

• 1st line calculates sqrt & assigns to local variable ‘r’

• 2nd line calculates expression & returns answer

MathCAD Programs #1• Programming Palette from toolbar• Select keywords from palette, DO

NOT TYPE• Add Line to add lines to program

• Watch selection box, carefully

MathCAD Programs #2• Assignments are local to program• Assignments in program use • Can use full range of MathCAD functions

in program• Last line is result of program• Use Vectors & Arrays to return multiple

results

MathCAD ProgramsOnline Help

• Tutorials– Getting started Defining functions– Features In-Depth Programming

• Quicksheets– Programming

Review of Lecture