%gas_speed_distribution.m
%Velocity Distribution of N nitrogen molecules
%Danny Marzahl, Steven Sahyun, 2-9-2016, UW-Whitewater
%sahyuns@uww.edu
clc;
clf;
clear;
%Variables: v (velocity) range 0-1600 in units m/s
%t (temperature) range 300-900 in units K
k = 1.380e-23;%j/K Boltzmann constant.
mass = 4.65e-26;%kg Mass of a nitrogen molecule.
N = 1e5;%Number of nitrogen molecules
%set up x vector for plot grid
xplotwidth = 100;
xmin = 0;
xmax = xmin+xplotwidth;
xstep = (xmax-xmin)/100; %100 data points
x = xmin:xstep:xmax;
x0 = 0*x+1;
%set up y vector for plot grid.
yplotwidth = 100;
ymin = 0; %Change the start point in terms of # of standard deviations
ymax = yplotwidth; %Change the end point in terms of # of standard deviations
ystep = (ymax-ymin)/100; %100 data points
y = ymin:ystep:ymax;
y0 = 0*y+1;
%create mesh grid
meshgrid(x,y);
%create a z matrix from x and y and fill with 0
z = y0'*x0;
z(:,:)=0;
%set low and high volumes to plot and set for 100 data points between
vlow = 0; %low velocity in m/s
vhigh = 1600;%high velocity in m/s
dv = (vhigh-vlow)/100;
v = vlow:dv:vhigh; %e14hz
%set low and high temperatures and step range for 100 data points between
tlow = 300; %low temperature in K
thigh = 900; %high temperature in k
dt = (thigh-tlow)/100; %100 steps
tstepmax = tlow+100*dt;
%this is just to get it to look nice on the plot withouth having to set
%the axis.
zscale =.4;
%fill the z matrix with Speed Distribution graphs
%(equation from Serway, Physics for Scientists and Engineers, 3rd Ed. pg 575) for each row changing the work function by
%dw
for tstep = 1:101;
t = tlow+dt*tstep;%go from tlow to thigh in 100 steps of size dt
Nv = (4 .*pi .*N .*(mass ./(2 .*pi .*k .*t)) .^(3/2) .*(v .^2 .*exp(-mass .*v .^2 ./(2 .*k .*t))));
A = zscale*y0'*Nv; %create a temporary matrix
z(tstep,:)=A(tstep,:); %copy only row of interest into the z matrix
end
%plot the Photoelectric Effect
figure(1)
plot(v, Nv);
%show a 3D plot of the Speed Distribution
figure(2)
surf(v, tlow+y*dt, z);
%Convert to a 3D printable file; You need to have stlwrite.m and surf2solid.m by
%Sven Holcombe in the same directory as this file.
%See: http://jmumakerlab.blogspot.com/2013/11/exporting-stl-from-matlab.html
% http://www.mathworks.com/matlabcentral/fileexchange/42876-surf2solid-make-a-solid-volume-from-a-surface-for-3d-printing
% http://www.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-filename--varargin-
Nv = surf2solid(x, y, z, 'Elevation', -1);
stlwrite('gas_speed_distribution.stl',Nv)