Dip

%************************************************

%* Name: Dip Patel Date: 2/25/15                *

%* File: FluidMechanicsProgram.m                *

%* Instructor: DMG 12:40                        *

%************************************************

 

fprintf (‘\n’)

fprintf (‘\n************************************************’)

fprintf (‘\n* Name: Dip Patel Date: 2/25/15                *’)

fprintf (‘\n* File: FluidMechanicsProgram.m                *’)

fprintf (‘\n* Instructor: DMG 12:40                        *’)

fprintf (‘\n************************************************’)

fprintf (‘\n’)

 

%Info Section

fprintf (‘Hello. This program will calculate the missing variable of\n’)

fprintf (‘the Volumetric Flow Rate Equation, and will also calculate\n’)

fprintf (‘the average velocity, shear stress at the wall, hydraulic\n’)

fprintf (‘diameter, reynolds number, and entrance length. This program\n’)

fprintf (‘will then plot the velocity and shear stress across the length\n’)

fprintf (‘of the channel.\n’)

fprintf (‘Instructions: Enter value if available, -1 if not.\n’)

 

%Data Input by User

q = input(‘Volumetric Flow Rate: ‘);

w = input(‘Width: ‘);

h = input(‘Height: ‘);

l = input(‘Length: ‘);

p = input(‘Delta P: ‘);

u = input(‘Viscosity: ‘);

 

fprintf(‘\n’)

 

%If else ladder to determine what is missing, and to calculate its value

%and display it to the screen

if q == -1

   q = (w*(h^3)*p)/(12*u*l);

   fprintf(‘Volumetric Flow Rate: \t%.3f cm^3/s\n’, q)

elseif w == -1

   w = (12*u*l*q)/((h^3)*p);

   fprintf(‘Width: \t%.3f cm\n’, w)

elseif h == -1

   h = ((12*u*l*q)/(w*p))^-3;

   fprintf(‘Height: \t%.3f cm\n’, h)

elseif l == -1

   l = (w*(h^3)*p)/(12*u*q);

   fprintf(‘Length: \t%.3f cm\n’, l)

elseif p == -1

   p = (12*u*l*q)/((h^3)*w);

   fprintf(‘Delta P: \t%.3f dynes/cm\n’, p)

elseif u == -1

   u = (w*(h^3)*p)/(12*l*q);

   fprintf(‘Viscosity: \t%.3f g/cm*s\n’, u)

else

end

 

%calculate supplementary values

Vavg = ((h^2)*p)/(12*u*l);

tau = ((h/2)*p)/l;

Dh = (4*w*h)/((2*w)+(2*h));

Re = (Vavg*Dh)/u;

Le = 0.06*Re*Dh;

 

%print out all calculated values

fprintf(‘Average Velocity: \t\t%.3f cm/s\n’, Vavg)

fprintf(‘Shear Stress at Wall: \t%.3f dynes/cm^2\n’, tau)

fprintf(‘Hydraulic Diameter: \t%.3f cm\n’, Dh)

fprintf(‘Reynolds Number: \t\t%.3f\n’, Re)

fprintf(‘Entrance Length: \t\t%.3f cm\n’, Le)

 

%array of different places across the channel, for use later

y = linspace(-h/2,h/2,250);

 

%use for loop to calculate

for i = 1:1:250

  V(i) = (p/8*u*l)*((h^2)-4*((y(i)))^2);

  T(i) = (p*abs(y(i)))/l;

end

 

plot(y,V,’-‘)

xlabel(‘Distance Across Channel (cm)’)

ylabel(‘Velocity (cm/s)’)

title(‘Velocity Across Channel’)

 

figure

 

plot(y,T, ‘-‘)

xlabel(‘Distance Across Channel (cm)’)

ylabel(‘Shear Stress (dynes/cm^2)’)   

title(‘Shear Stress Across Channel’)