PH24010 - MathCAD: Histograms, statistics and randomness

Download Report

Transcript PH24010 - MathCAD: Histograms, statistics and randomness

PH24010
MathCAD
Statistics, Random Numbers &
Histograms
Distribution Functions
• dnorm(x, , )
– Normal distribution
0.4
dnorm x     
0.2
• pnorm(x, , )
– Cumulative Normal
distribution
– Equal to
x

      dx 

dn ormx
 
0
4
2
0
x
2
4
4
2
0
x
2
4
1
dnorm x     
pnorm x     
0.5
0
Other distributions
• Poisson
– dpois(r,l) ppois(r,l)
– r events in distribution with mean l
• Binomial
– dbinom(k,n,p) pbinom(k,n,p)
– k success in n trials, probability p
• Exponential
– dexp(x,r)
– Exponential distribution, decay rate r
Histograms
• histogram(Intvls, Data)
• Returns Matrix
• Results<0>
– Midpoints of intervals
• Results<1>
30
20
Counts
10
– Count per bin
0
3
2
1
0
Bins
1
2
3
The Intervals vector
• Gives endpoints of
intervals
• n elements in
vector
•  n-1 midpoints
• Watch for
Fencepost error
• Off-by-one-error
– Obi-One-’kin-Error
0
1
 
Intervals   2 
3
 
4
 0.5 
 
1.5 

midp oints

 2.5 
 
 3.5 
Generating the Intervals Vector
• Program
• Local
Variables
• for loop
• Use
programming
toolbar
• Test program
IntervalVector( amin amax Np )  
a 
amax amin
Np
for i  0  Np
Resulti  amin a i
Result
0 
 
2 
4 
IntervalVector( 0  10  5)   
6 
8 
 
 10 
Coins, Dice & other random things
• rnd(x)  random number in range 0 to x
• manipulate to get desire result
• rnd(1)>0.5 will give
– 0 for 50% and
– 1 for 50%
– True=1, false =0
• int(rnd(6)) gives number 0 to 5
Other Random Distributions
Return vector of m numbers
•
•
•
•
rnd(m,a,b)  uniform distribution
rnorm(m, , )  normal distribution
rpois(m,l)  Poisson distribution
rexp(m,r)  exponential distribution
• ++ others
• see f(x) & help
Pseudo-Randomness & seed
•
•
•
•
•
Numbers generated in sequence
Same sequence every time worksheet run
SEED variable sets start point in sequence
Integer from 1 to 2147483647
Change seed with
– Tools|Worksheet Options|Built-in variables
– Seed(x)
• Seed(trunc(time(0)))