Chapter 5&6 Histograms Plots
Histogram A frequency distribution shown in graphical form. Frequency: Number of times that a data value occurs in the data set.
Example of Frequency Distribution IntervalFrequency 150 x < x < x < x < x < x < x <220 2
Histogram Construction > Count the number of observations (n) > Find the largest & smallest value > Find the range (largest-smallest) > Determine the number and width of the class intervals by the following rules:
Rules > Use from 5 to 20 intervals. ROT: # of Intervals = n 1/2 > Choose the lower limit for the first cell by using a value that is slightly less than the smallest data value. > The class interval (width) can be determined by w = range/number of cells.
Histogram Construction > Tally Data for each Interval > Draw Rectangular Boxes with heights equal to the frequencies of the number of observations.
Histograms Functions (MATLAB) hist(y) >>> Plots with 10 equally spaced bins. hist(y, nbins ) >>> Plots with nbins equally spaced bins.
User-Defined Functions A type of M-file that runs in its own independent workspace. function [ output variables ]= f_name( input Example: variables ); function k=sun(r,s) k=r*s; >>z=sun(2,3) z= 6
Example User Defined Functions Calculate Distance between two points: >function distance=dist2 (x1, y1, x2, y2); >distance=sqrt((x2-x1).^2+(y2-y1).^2); In the program: >>result= dist2(ax, ay, bx, by);
Problem: User-Defined Functions Create a function to calculate the kinetic energy of a moving object: KE = ½ mv 2