PH24010 - Statistics with MathCAD

Download Report

Transcript PH24010 - Statistics with MathCAD

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
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
MyVector
1
MyVector
2
3
1
MyVector
m

2
s
3
• Placeholders to fill in
• Can use units
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
VA
12
666
VA0  12
VA0
VA 
42
42
666
VA1  666
• Simple 2 element
vector
• Examine elements
• Set element 0
• Result of setting
Indices #2
Matrix Example
1
MA
2
3
999 42 666
MA0  0  1
MA0  1  2
MA0  3 
MA1  0
MA 
27
1
2
3
27 42 666
•
•
MA0  2  3
•
•
•
Sample matrix
Examine elements
Subscript too big
Set element
Result
Statistical Functions
on Vectors #1
• From f(x) dialog box under “Statistics”
• Averaging
– mean() ‘Average value’
– median() ‘Half way item’
– mode() ‘Most common value’
Statistical Functions
on 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
 Expression
n l
 Expression
n
Summation #3
5
i  15
• Sum of first 5 integers
i= 1
30
Countsi  9
i = 20
• Sum of elements 2030 of vector Counts
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
fExample( a  b) 
cos
2
a b
2

2
2
2
a b
2
2 a  b
• Common subexpression calculated 3 times in
function
•  Can re-write using a program
fExample(a,b) as a 2 line
program
fExample( a  b) 
2
r a  b
cos( r)
2r
2
r
• 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 Programs
Online Help
• Tutorials
– Getting started Defining functions
– Features In-Depth  Programming
• Quicksheets
– Programming
Review of Lecture