Test Forum B5 FAQ

genstat.m

Thread Tools
 
Search this Thread
 
Old Jun 28, 2002 | 12:59 PM
  #1  
SuspendedLikeaMoFo.'s Avatar
Thread Starter
Elder Member
 
Joined: Mar 2000
Posts: 12,893
Likes: 0
Default genstat.m

% GENSTAT.M calculates the projectile range
% 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)
Reply
Old Jun 28, 2002 | 12:59 PM
  #2  
SuspendedLikeaMoFo.'s Avatar
Thread Starter
Elder Member
 
Joined: Mar 2000
Posts: 12,893
Likes: 0
Default genx.m

function x = genx (np, ns, mean, sigma)
% 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 ];
Reply
Old Jun 28, 2002 | 01:00 PM
  #3  
SuspendedLikeaMoFo.'s Avatar
Thread Starter
Elder Member
 
Joined: Mar 2000
Posts: 12,893
Likes: 0
Default hgramf.m

function hgramf (data_vector)
% 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)
Reply
Old Jun 28, 2002 | 01:00 PM
  #4  
SuspendedLikeaMoFo.'s Avatar
Thread Starter
Elder Member
 
Joined: Mar 2000
Posts: 12,893
Likes: 0
Default histdemo.m

% HISTDEMO.M is a Histogram-generating program

%=================================================
% 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)
Reply
Old Jun 28, 2002 | 01:01 PM
  #5  
SuspendedLikeaMoFo.'s Avatar
Thread Starter
Elder Member
 
Joined: Mar 2000
Posts: 12,893
Likes: 0
Default histdemo2.m

% HISTDEMO.M is a Histogram-generating program

%=================================================
% 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)
Reply
Old Jun 28, 2002 | 01:01 PM
  #6  
SuspendedLikeaMoFo.'s Avatar
Thread Starter
Elder Member
 
Joined: Mar 2000
Posts: 12,893
Likes: 0
Default normpdf.m

function p = normpdf ( x, mean, sigma )
% 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 );
Reply
Old Jun 28, 2002 | 01:01 PM
  #7  
SuspendedLikeaMoFo.'s Avatar
Thread Starter
Elder Member
 
Joined: Mar 2000
Posts: 12,893
Likes: 0
Default p_data38.txt

4.95
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
Reply
Old Jun 28, 2002 | 01:02 PM
  #8  
SuspendedLikeaMoFo.'s Avatar
Thread Starter
Elder Member
 
Joined: Mar 2000
Posts: 12,893
Likes: 0
Default range0.m

function R = range0( V0, theta0, x0, z0 )
% 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;
Reply
AudiWorld Stories

Bringing Audi to Life for Audi Fans

story-0

New Audi A6 Allroad Is The Market's Coolest Wagon: 9 Things to Know

 Pouria Savadkouei
story-1

10 Strangest Audi Designs That Actually Made Production

 Joe Kucinski
story-2

2027 Audi Q7 and SQ7: Audi Upgraded EVERYTHING!

 Michael S. Palmer
story-3

Audi Unveils Absurdly Cool New Supercar: 10 Things You Need to Know!

 Verdad Gallardo
story-4

The Highs & Lows of Every Audi C-Class Generation

 Joe Kucinski
story-5

Top 10 Most Expensive Audis Ever Sold on Bring-A-Trailer

 Brett Foote
story-6

10 Audi Features & Options We Miss the Most!

 Joe Kucinski
story-7

Audi Recreates Crazy-Looking Speed Record Breaker From 1935

 Verdad Gallardo
story-8

Coachbuilder Recreates the 1995 Audi TTS Concept

 Verdad Gallardo
story-9

Every Audi V10 Car Ranked!

 Joe Kucinski
Old Jun 28, 2002 | 01:02 PM
  #9  
SuspendedLikeaMoFo.'s Avatar
Thread Starter
Elder Member
 
Joined: Mar 2000
Posts: 12,893
Likes: 0
Default readdata.m

[velocity] = textread('p_data.txt','%f',...
'headerlines',0)
Reply
Old Jun 28, 2002 | 01:02 PM
  #10  
SuspendedLikeaMoFo.'s Avatar
Thread Starter
Elder Member
 
Joined: Mar 2000
Posts: 12,893
Likes: 0
Default stats.m

function [ mean, std_dev ] = stats ( x )
% 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 );
Reply



All times are GMT -8. The time now is 01:17 AM.

story-0
New Audi A6 Allroad Is The Market's Coolest Wagon: 9 Things to Know

Slideshow: Audi's latest A6 Allroad gets RS-style fenders, real off-road hardware, and enough personality to stand out in a market obsessed with crossovers.

By Pouria Savadkouei | 2026-06-16 17:31:52


VIEW MORE
story-1
10 Strangest Audi Designs That Actually Made Production

Slideshow: 10 strangest Audi designs that actually made production

By Joe Kucinski | 2026-06-10 16:32:29


VIEW MORE
story-2
2027 Audi Q7 and SQ7: Audi Upgraded EVERYTHING!

Slideshow: Everything you need to know about the 2027 Audi Q7 and SQ7

By Michael S. Palmer | 2026-06-09 06:02:56


VIEW MORE
story-3
Audi Unveils Absurdly Cool New Supercar: 10 Things You Need to Know!

Slideshow: Limited to just 499 units, the 987-horsepower halo car signals a new chapter for Audi performance.

By Verdad Gallardo | 2026-06-04 17:37:15


VIEW MORE
story-4
The Highs & Lows of Every Audi C-Class Generation

Slideshow: The highs and lows of every Audi C-Class generation.

By Joe Kucinski | 2026-05-27 16:05:50


VIEW MORE
story-5
Top 10 Most Expensive Audis Ever Sold on Bring-A-Trailer

People were more than happy to shell out big bucks for these cars.

By Brett Foote | 2026-05-27 15:32:23


VIEW MORE
story-6
10 Audi Features & Options We Miss the Most!

Slideshow: 10 Audi features and options we miss the most.

By Joe Kucinski | 2026-05-12 19:33:47


VIEW MORE
story-7
Audi Recreates Crazy-Looking Speed Record Breaker From 1935

Slideshow: Audi has recreated one of the wildest machines of the pre-war speed-record era, reviving a streamlined V16 racer that originally exceeded 200 mph in 1935.

By Verdad Gallardo | 2026-05-11 09:49:34


VIEW MORE
story-8
Coachbuilder Recreates the 1995 Audi TTS Concept

Slideshow: A Dutch coachbuilder has reimagined the original Audi TT by finishing what the 1995 concept only hinted at.

By Verdad Gallardo | 2026-05-05 15:17:58


VIEW MORE
story-9
Every Audi V10 Car Ranked!

Slideshow: Ranking every Audi V10 road car

By Joe Kucinski | 2026-04-29 16:11:56


VIEW MORE