genstat.m
% using a set of launch angles derived from
% random samples from a normal distribution
% Rid the screen of clutter
clc
% Display a banner
disp ( '**********************************' )
disp ( '* PROGRAM GENSTAT.M *' )
disp ( '**********************************' )
% Get the number of samples from the user
num_samples = input ( '\nEnter the number of samples: ' );
% Get the desired mean and standard deviation
desired_mean = input ( '\nEnter the mean: ' );
desired_std = input ( '\nEnter the standard deviation: ');
% Calculate the sample vector
theta0 = desired_std*randn(1, num_samples) + desired_mean;
fprintf( '\nLaunch angle samples\n' );
fprintf( ' %10.5f\n', theta0' );
% Calculate the range
fprintf ('\n\n')
V0 = input ('Enter desired launch velocity (m/s): ');
x0 = input ('Enter desired initial x-position (m): ');
z0 = input ('Enter desired initial z-position (m): ');
fprintf ( '\nCalculating range vector...\n' )
R = range0( V0, theta0, x0, z0 );
% Mean and standard deviation of R
[mean_of_R, sigma_of_R] = stats (R);
fprintf ('\nThe mean R is %10.5f (m)', mean_of_R )
fprintf ('\nThe standard deviation of R is %10.5f (m)\n\n', sigma_of_R)
% GENX.M generates a vector x of data values
% between mean-n*sigma and mean+n*sigm
%===========================================
% np = number of points to generate
% ns = 2*ns is the width of x in sigmas
% mean = mean of x
% sigma = standard deviation of x
%===========================================
x = [ mean-ns*sigma: 2*sigma/np: mean+ns*sigma ];
% Histogram-generating function
%=================================================
% bin_centers = vector containing centers of bins
% data_vector = vector of pressure measurments
% frequency = vector giving fractional number
% of measurements in each bin.
% m = number of bins in histogram
% n = number of measurements in each bin
% num_meas = number of measurements
%=================================================
% Clear the clutter
clc
% Set up m, equally-spaced histogram bins
m = input ( '\n Enter the number of equally-spaced bins: ' );
% Number in each (n) bin and bin centers
[n, bin_centers] = hist (data_vector, m);
% Set up a subplot array with
% 1 row, 2 columns, and the histogram
% in the 1st column
subplot (1, 2, 1)
% Histogram
hist (data_vector, m), xlabel ('pressure (psi)'),...
ylabel ('quantity in bin'),...
title('Pressure Measurement Histogram');
% Put the bar chart in row 1, column 2
subplot (1, 2, 2)
% Frequency distribution
num_meas = length (data_vector); % A speed-up: num_meas used twice
frequency = n/num_meas;
bar (bin_centers, frequency), xlabel ('pressure (psi)'),...
ylabel ('frequency'),...
title('Pressure Measurement Frequency Distribution');
% Display bin data
fprintf ('\n There were %3.0f measurements.\n\n', num_meas);
disp (' bin Center (psi) count frequency')
A = [ bin_centers; n; frequency ]; % You have to put them in a matrix
fprintf (' %4.3f %2.0f %6.4f\n', A)
%=================================================
% bin_centers = vector containing centers of bins
% frequency = vector giving fractional number
% of measurements in each bin.
% m = number of bins in histogram
% n = number of measurements in each bin
% num_meas = number of measurements
% p_data = vector of pressure measurments
%=================================================
% Load the data
load p_data.txt
% Clear the clutter
clc
% Set up m, equally-spaced histogram bins
m = input ( '\n Enter the number of equally-spaced bins: ' );
% Number in each (n) bin and bin centers
[n, bin_centers] = hist (p_data, m);
% Set up a subplot array with
% 1 row, 2 columns, and the histogram
% in the 1st column
subplot (1, 2, 1)
% Histogram
hist (p_data, m), xlabel ('pressure (psi)'),...
ylabel ('quantity in bin'),...
title('Pressure Measurement Histogram');
% Put the bar chart in row 1, column 2
subplot (1, 2, 2)
% Frequency distribution
num_meas = length (p_data); % A speed-up: num_meas used twice
frequency = n/num_meas;
bar (bin_centers, frequency), xlabel ('pressure (psi)'),...
ylabel ('frequency'),...
title('Pressure Measurement Frequency Distribution');
% Display bin data
fprintf ('\n There were %3.0f measurements.\n\n', num_meas);
disp (' bin Center (psi) count frequency')
A = [ bin_centers; n; frequency ]; % You have to put them in a matrix
fprintf (' %4.3f %2.0f %6.4f\n', A)
%=================================================
% bin_centers = vector containing centers of bins
% frequency = vector giving fractional number
% of measurements in each bin.
% m = number of bins in histogram
% n = number of measurements in each bin
% num_meas = number of measurements
% p_data = vector of pressure measurments
%=================================================
% Load the data
load p_data.txt
% Clear the clutter
clc
% Set up m, equally-spaced histogram bins
m = input ( '\n Enter the number of equally-spaced bins: ' );
% Number in each (n) bin and bin centers
[n, bin_centers] = hist (p_data, m);
% Set up a subplot array with
% 1 row, 2 columns, and the histogram
% in the 1st column
%subplot (1, 2, 1)
% Histogram
%hist (p_data, m), xlabel ('pressure (psi)'),...
% ylabel ('quantity in bin'),...
% title('Pressure Measurement Histogram');
% Put the bar chart in row 1, column 2
%subplot (1, 2, 2)
% Frequency distribution
measurements = length (p_data); % A speed-up: num_meas used twice
frequency = n/measurements;
bar (bin_centers, frequency), xlabel ('pressure (psi)'),...
ylabel ('frequency'),...
title('Pressure Measurement Frequency Distribution');
% Display bin data
fprintf ('\n There were %3.0f measurements.\n\n', measurements);
disp (' bin Center (psi) count frequency')
A = [ bin_centers; n; frequency ]; % You have to put them in a matrix
fprintf (' %4.3f %2.0f %6.4f\n', A)
% NORMPDF.M calculates and plots a
% normal probability density function.
%===============================================
% mean = mean of the data vector, x
% sigma = standard deviation of data vector, x
% x = data vector over which to find p(x)
% p(x) = probability density function
%===============================================
normalizer = 1/(sigma*sqrt(2*pi));
p = normalizer*exp( -0.5*( (x - mean)/sigma ).^2 );
4.87
5.1
4.99
5.06
5.09
4.95
5.01
4.98
4.99
5.0
5.05
5.0
5.02
5.01
5.06
4.99
5.01
4.98
4.97
4.92
4.93
5.00
4.98
4.92
4.91
5.06
5.01
4.98
4.97
5.02
4.92
4.94
4.98
4.99
4.92
5.04
5.00
Trending Topics
% RANG0.M calculates the range given launch
% conditions and no drag.
%==========================================
% Variable definitions
% theta0 = launch angle (degrees)
% V0 = launch velocity (m/s)
% x0 = launch x-coordinate (m)
% z0 = launch z-coordinate (m)
%==========================================
% Specify constants
g = 9.807; % m/s^2
% Calculate Vx0, Vz0 (m/s)
theta0r = theta0*pi./180;
Vx0 = V0*cos( theta0r );
Vz0 = V0*sin( theta0r );
% Find the time of flight (s)
for j = 1:length(theta0)
c = [ -.5*g Vz0(j) z0 ];
the_roots_of_c = roots(c);
if the_roots_of_c(1) > 0
time_of_flight(j) = the_roots_of_c(1);
else
time_of_flight(j) = the_roots_of_c(2);
end
end
% Calculate the range
R = Vx0.*time_of_flight;
Bringing Audi to Life for Audi Fans
% STATS.M computes the mean and standard deviation
% of a vector of data.
%=========================================
% Variable definitions
% lengthx = the number of entries in x
% mean = the average of x
% std_dev = the standard deviation of x
% x = a vector containing sample
% of x
%=========================================
% Find the length of sample x
lengthx = length(x);
% Find the mean of the lengthx samples
mean = sum(x)/lengthx;
% Find the standard deviation of the samples
std_dev = sum( ( mean - x ).^2 )/(lengthx - 1 );


