Eman

%Standard Name and Class Information
fprintf (‘\n’)
fprintf (‘\n************************************************’)
fprintf (‘\n*  Name:  Eman Jallaq   Date:  02-26-16        *’)
fprintf (‘\n*  File:  Fluid Mechanics Program              *’)
fprintf (‘\n*  Instructor:  DMG 12:40                      *’)                       
fprintf (‘\n************************************************’)
fprintf (‘\n’)

%Brief Description of what the program does
fprintf (‘\n’)
fprintf (‘\n    This program is designed for a rectangular channel.’)
fprintf (‘\nAfter running the program, the user will have the ‘)
fprintf (‘\nsixth parameter of the channel based on the five’)
fprintf (‘\ninputted by the user, as well as the average velocity,’)
fprintf (‘\nthe sheer stress at the wall, the Reynolds number,’)
fprintf (‘\nand the entrance length. Along with all of these values’)
fprintf (‘\nand the design parameters outputted in a neatly formatted’)
fprintf (‘\ntable, a plot of both the velocity and sheer stress’)
fprintf (‘\ndistributions across the thickness of the channel will’)
fprintf (‘\nalso be generated. All units will be mentioned in the ‘)
fprintf (‘\ntable.’)
fprintf (‘\n’)

%Instructions on How To Use the Program
fprintf (‘\n’)
fprintf (‘\nThis program is easy to use. It runs as follows:’)
fprintf (‘\n1. The program will give a list of all of the’)
fprintf (‘\npossible parameters the user may input.’)
fprintf (‘\n2. After that list is displayed, the program will’)
fprintf (‘\nask which parameter is missing/unknown.’)
fprintf (‘\n3. From there, the program will then ask for an’)
fprintf (‘\ninput of the known parameters, with specific units’)
fprintf (‘\nfor each parameter given.’)
fprintf (‘\n4. Once all of the known parameters have been’)
fprintf (‘\ninputted into the program, the program will calculate’)
fprintf (‘\nthe missing parameter, average velocity, sheer stress’)
fprintf (‘\nat the wall, Reynolds number, and entrance length.’)
fprintf (‘\n5. The program will then display all parameters and’)
fprintf (‘\ncalculations in a neatly formatted chart with units’)
fprintf (‘\nfor each value.’)
fprintf (‘\n6. After the table is displayed, a plot with velocity’)
fprintf (‘\nand sheer stress across the channel will be displayed,’)
fprintf (‘\nincluding proper units and labels.’)
fprintf (‘\n’)

%Give list of possible parameters to input
fprintf (‘\n’)
fprintf (‘\nThe 6 possible input parameters are:’)
fprintf (‘\n1. Volumetric Flow Rate’)
fprintf (‘\n2. Width’)
fprintf (‘\n3. Height’)
fprintf (‘\n4. Length’)
fprintf (‘\n5. Delta P’)
fprintf (‘\n6. Viscosity’)
fprintf (‘\n’)

%Ask which parameter is missing
fprintf (‘\nNow let us see which parameter is missing.\n’)
fprintf (‘Volumetric Flow Rate = 1; Width = 2; Height = 3; Length = 4;\n’)
fprintf (‘Delta P = 5; and Viscosity = 6.\n’)
prompt = ‘\nPlease enter the value corresponding with the missing parameter\n’;
x = input(prompt);

%Ask for the density of the fluid that’s being worked with
like = ‘\nWhat is the density of the fluid being worked with in g/(cm^3)?\n’;
d = input(like);

%Calculate the Missing Parameter
switch x
   case 1
       fprintf (‘\nOkay great! The value will be calculated once’)
       fprintf (‘\na litte more information is given. Please enter the known’)
       fprintf (‘\nparameters when requested in the proper units.\n’)
       
       %Enter Width
       prompt2=’\nPlease enter width in centimeters.\n’;
       w = input(prompt2);
       
       %Enter Height
       prompt3=’Please enter height in centimeters.\n’;
       h = input(prompt3);
       
       %Enter Length
       prompt4=’Please enter length in centimeters.\n’;
       l = input(prompt4);
       
       %Enter Delta P
       prompt5=’Please enter Delta P in dyne/(cm^2).\n’;
       p = input(prompt5);
       
       %Enter Viscosity
       prompt6=’Please enter Viscosity in g/(cm*s).\n’;
       vi = input(prompt6);
       
       %Time to calculate the missing parameter
       fprintf (‘\nOkay good! Now that all of the known parameters’)
       fprintf (‘\nhave been inputted, we can calculate the Volumetric’)
       fprintf (‘\nFlow Rate.\n’)
       q = (w * h * h * h * p)/(12 * vi * l);
       
       %Results Calculations
       vavg = (h * h * p)/(12 * vi * l);
       dh = (4 * w * h)/(2 * (w + h));
       ss = ((h/2) * p)/l;
       re = (d * dh * vavg)/vi;
       el = .06 * re * dh;
       
       %Table of Values
       fprintf (‘\n’)
       fprintf (‘\nHere is the table containing all of the parameters’)
       fprintf (‘\nand the results calculations, along with units.\n’)
       fprintf (‘\n    Results/Parameters     Value     Units’)
       fprintf (‘\n   Volumetric Flow Rate      %f     (cm^3)/s ‘,q)
       fprintf (‘\n         Width               %f        cm ‘,w)
       fprintf (‘\n        Height               %f        cm ‘,h)
       fprintf (‘\n        Length               %f        cm ‘,l)
       fprintf (‘\n        Delta P              %f     dyne/(cm^2) ‘,p)
       fprintf (‘\n       Viscosity             %f      g/(cm*s) ‘,vi)
       fprintf (‘\n    Average Velocity         %f       cm/s ‘,vavg)
       fprintf (‘\n Sheer Stress at the Wall    %f    dyne/(cm^2) ‘,ss)
       fprintf (‘\n     Reynolds Number         %f     unitless ‘,re)
       fprintf (‘\n     Entrance Length         %f        cm \n’,el)
       
       %Plot of Velocity and Sheer Stress across Channel
       fprintf (‘\nAnd now the plots.\n’)
       j = linspace(0,l,l);
       jj= j.*j;
       vf=p *((h*h)-(4.*jj))./(8*vi*l);
       ssf=p.*abs(j)./l;
       plot(j,vf)
       %labels and titles
       title(‘Velocity Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Velocity(cm/s)’)
       %Open up another image for the sheer stress plot
       figure
       plot(j,ssf)
       %title and labels
       title(‘Sheer Stress Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Sheer Stress (dyne/(cm^2))’)
       
  case 2
   fprintf (‘\nOkay great! The value will be calculated once’)
       fprintf (‘\na litte more information is given. Please enter the known’)
       fprintf (‘\nparameters when requested in the proper units.\n’)
       
       %Enter Volumetric Flow Rate
       prompt1=’\nPlease enter volumetric flow rate in (cm^3)/s.\n’;
       q = input(prompt1);
       
       %Enter Height
       prompt3=’Please enter height in centimeters.\n’;
       h = input(prompt3);
       
       %Enter Length
       prompt4=’Please enter length in centimeters.\n’;
       l = input(prompt4);
       
       %Enter Delta P
       prompt5=’Please enter Delta P in dyne/(cm^2).\n’;
       p = input(prompt5);
       
       %Enter Viscosity
       prompt6=’Please enter Viscosity in g/(cm*s).\n’;
       vi = input(prompt6);
       
       %Time to calculate the missing parameter
       fprintf (‘\nOkay good! Now that all of the known parameters’)
       fprintf (‘\nhave been inputted, we can calculate the Volumetric’)
       fprintf (‘\nFlow Rate.\n’)
       w=(12*q*vi*l)/(p*h*h*h);
       
       %Results Calculations
       vavg = (h * h * p)/(12 * vi * l);
       dh = (4 * w * h)/(2 * (w + h));
       ss = ((h/2) * p)/l;
       re = (d * dh * vavg)/vi;
       el = .06 * re * dh;
       
       %Table of Values
       fprintf (‘\n’)
       fprintf (‘\nHere is the table containing all of the parameters’)
       fprintf (‘\nand the results calculations, along with units.\n’)
       fprintf (‘\n    Results/Parameters     Value     Units’)
       fprintf (‘\n   Volumetric Flow Rate      %f     (cm^3)/s ‘,q)
       fprintf (‘\n         Width               %f        cm ‘,w)
       fprintf (‘\n        Height               %f        cm ‘,h)
       fprintf (‘\n        Length               %f        cm ‘,l)
       fprintf (‘\n        Delta P              %f     dyne/(cm^2) ‘,p)
       fprintf (‘\n       Viscosity             %f      g/(cm*s) ‘,vi)
       fprintf (‘\n    Average Velocity         %f       cm/s ‘,vavg)
       fprintf (‘\n Sheer Stress at the Wall    %f    dyne/(cm^2) ‘,ss)
       fprintf (‘\n     Reynolds Number         %f     unitless ‘,re)
       fprintf (‘\n     Entrance Length         %f        cm \n’,el)
       
       %Plot of Velocity and Sheer Stress across Channel
       fprintf (‘\nAnd now the plots.\n’)
       j = linspace(0,l,l);
       jj= j.*j;
       vf=p *((h*h)-(4.*jj))./(8*vi*l);
       ssf=p.*abs(j)./l;
       plot(j,vf)
       %labels and titles
       title(‘Velocity Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Velocity(cm/s)’)
       %Open up another image for the sheer stress plot
       figure
       plot(j,ssf)
       %title and labels
       title(‘Sheer Stress Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Sheer Stress (dyne/(cm^2))’)
       
   case 3
   fprintf (‘\nOkay great! The value will be calculated once’)
       fprintf (‘\na litte more information is given. Please enter the known’)
       fprintf (‘\nparameters when requested in the proper units.\n’)
       
       %Enter Volumetric Flow Rate
       prompt1=’\nPlease enter volumetric flow rate in (cm^3)/s.\n’;
       q = input(prompt1);
       
       %Enter Width
       prompt2=’\nPlease enter width in centimeters.\n’;
       w = input(prompt2);
       
        %Enter Length
       prompt4=’Please enter length in centimeters.\n’;
       l = input(prompt4);
       
       %Enter Delta P
       prompt5=’Please enter Delta P in dyne/(cm^2).\n’;
       p = input(prompt5);
       
       %Enter Viscosity
       prompt6=’Please enter Viscosity in g/(cm*s).\n’;
       vi = input(prompt6);
       
       %Time to calculate the missing parameter
       fprintf (‘\nOkay good! Now that all of the known parameters’)
       fprintf (‘\nhave been inputted, we can calculate the Volumetric’)
       fprintf (‘\nFlow Rate.\n’)
       h=(12*q*vi*l/(w*p))^(1/3);
       
       %Results Calculations
       vavg = (h * h * p)/(12 * vi * l);
       dh = (4 * w * h)/(2 * (w + h));
       ss = ((h/2) * p)/l;
       re = (d * dh * vavg)/vi;
       el = .06 * re * dh;
       
       %Table of Values
       fprintf (‘\n’)
       fprintf (‘\nHere is the table containing all of the parameters’)
       fprintf (‘\nand the results calculations, along with units.\n’)
       fprintf (‘\n    Results/Parameters     Value     Units’)
       fprintf (‘\n   Volumetric Flow Rate      %f     (cm^3)/s ‘,q)
       fprintf (‘\n         Width               %f        cm ‘,w)
       fprintf (‘\n        Height               %f        cm ‘,h)
       fprintf (‘\n        Length               %f        cm ‘,l)
       fprintf (‘\n        Delta P              %f     dyne/(cm^2) ‘,p)
       fprintf (‘\n       Viscosity             %f      g/(cm*s) ‘,vi)
       fprintf (‘\n    Average Velocity         %f       cm/s ‘,vavg)
       fprintf (‘\n Sheer Stress at the Wall    %f    dyne/(cm^2) ‘,ss)
       fprintf (‘\n     Reynolds Number         %f     unitless ‘,re)
       fprintf (‘\n     Entrance Length         %f        cm \n’,el)
       
       %Plot of Velocity and Sheer Stress across Channel
       fprintf (‘\nAnd now the plots.\n’)
       j = linspace(0,l,l);
       jj= j.*j;
       vf=p *((h*h)-(4.*jj))./(8*vi*l);
       ssf=p.*abs(j)./l;
       plot(j,vf)
       %labels and titles
       title(‘Velocity Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Velocity(cm/s)’)
       %Open up another image for the sheer stress plot
       figure
       plot(j,ssf)
       %title and labels
       title(‘Sheer Stress Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Sheer Stress (dyne/(cm^2))’)
       
  case 4
   fprintf (‘\nOkay great! The value will be calculated once’)
       fprintf (‘\na litte more information is given. Please enter the known’)
       fprintf (‘\nparameters when requested in the proper units.\n’)
       
       %Enter Volumetric Flow Rate
       prompt1=’\nPlease enter volumetric flow rate in (cm^3)/s.\n’;
       q = input(prompt1);
       
       %Enter Width
       prompt2=’\nPlease enter width in centimeters.\n’;
       w = input(prompt2);
       
       %Enter Height
       prompt3=’Please enter height in centimeters.\n’;
       h = input(prompt3);
       
       %Enter Delta P
       prompt5=’Please enter Delta P in dyne/(cm^2).\n’;
       p = input(prompt5);
       
       %Enter Viscosity
       prompt6=’Please enter Viscosity in g/(cm*s).\n’;
       vi = input(prompt6);
       
       %Time to calculate the missing parameter
       fprintf (‘\nOkay good! Now that all of the known parameters’)
       fprintf (‘\nhave been inputted, we can calculate the Volumetric’)
       fprintf (‘\nFlow Rate.\n’)
       l=(w*h*h*h*p)/(12*q*vi);
       
       %Results Calculations
       vavg = (h * h * p)/(12 * vi * l);
       dh = (4 * w * h)/(2 * (w + h));
       ss = ((h/2) * p)/l;
       re = (d * dh * vavg)/vi;
       el = .06 * re * dh;
       
       %Table of Values
       fprintf (‘\n’)
       fprintf (‘\nHere is the table containing all of the parameters’)
       fprintf (‘\nand the results calculations, along with units.\n’)
       fprintf (‘\n    Results/Parameters     Value     Units’)
       fprintf (‘\n   Volumetric Flow Rate      %f     (cm^3)/s ‘,q)
       fprintf (‘\n         Width               %f        cm ‘,w)
       fprintf (‘\n        Height               %f        cm ‘,h)
       fprintf (‘\n        Length               %f        cm ‘,l)
       fprintf (‘\n        Delta P              %f     dyne/(cm^2) ‘,p)
       fprintf (‘\n       Viscosity             %f      g/(cm*s) ‘,vi)
       fprintf (‘\n    Average Velocity         %f       cm/s ‘,vavg)
       fprintf (‘\n Sheer Stress at the Wall    %f    dyne/(cm^2) ‘,ss)
       fprintf (‘\n     Reynolds Number         %f     unitless ‘,re)
       fprintf (‘\n     Entrance Length         %f        cm \n’,el)
       
       %Plot of Velocity and Sheer Stress across Channel
       fprintf (‘\nAnd now the plots.\n’)
       j = linspace(0,l,l);
       jj= j.*j;
       vf=p *((h*h)-(4.*jj))./(8*vi*l);
       ssf=p.*abs(j)./l;
       plot(j,vf)
       %labels and titles
       title(‘Velocity Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Velocity(cm/s)’)
       %Open up another image for the sheer stress plot
       figure
       plot(j,ssf)
       %title and labels
       title(‘Sheer Stress Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Sheer Stress (dyne/(cm^2))’)
       
   case 5
    fprintf (‘\nOkay great! The value will be calculated once’)
       fprintf (‘\na litte more information is given. Please enter the known’)
       fprintf (‘\nparameters when requested in the proper units.\n’)
       
       %Enter Volumetric Flow Rate
       prompt1=’\nPlease enter volumetric flow rate in (cm^3)/s.\n’;
       q = input(prompt1);
       
       %Enter Width
       prompt2=’\nPlease enter width in centimeters.\n’;
       w = input(prompt2);
       
       %Enter Height
       prompt3=’Please enter height in centimeters.\n’;
       h = input(prompt3);
       
        %Enter Length
       prompt4=’Please enter length in centimeters.\n’;
       l = input(prompt4);

       %Enter Viscosity
       prompt6=’Please enter Viscosity in g/(cm*s).\n’;
       vi = input(prompt6);
       
       %Time to calculate the missing parameter
       fprintf (‘\nOkay good! Now that all of the known parameters’)
       fprintf (‘\nhave been inputted, we can calculate the Volumetric’)
       fprintf (‘\nFlow Rate.\n’)
       p=(q*12*vi*l)/(w*h*h*h);
       
       %Results Calculations
       vavg = (h * h * p)/(12 * vi * l);
       dh = (4 * w * h)/(2 * (w + h));
       ss = ((h/2) * p)/l;
       re = (d * dh * vavg)/vi;
       el = .06 * re * dh;
       
       %Table of Values
       fprintf (‘\n’)
       fprintf (‘\nHere is the table containing all of the parameters’)
       fprintf (‘\nand the results calculations, along with units.\n’)
       fprintf (‘\n    Results/Parameters     Value     Units’)
       fprintf (‘\n   Volumetric Flow Rate      %f     (cm^3)/s ‘,q)
       fprintf (‘\n         Width               %f        cm ‘,w)
       fprintf (‘\n        Height               %f        cm ‘,h)
       fprintf (‘\n        Length               %f        cm ‘,l)
       fprintf (‘\n        Delta P              %f     dyne/(cm^2) ‘,p)
       fprintf (‘\n       Viscosity             %f      g/(cm*s) ‘,vi)
       fprintf (‘\n    Average Velocity         %f       cm/s ‘,vavg)
       fprintf (‘\n Sheer Stress at the Wall    %f    dyne/(cm^2) ‘,ss)
       fprintf (‘\n     Reynolds Number         %f     unitless ‘,re)
       fprintf (‘\n     Entrance Length         %f        cm \n’,el)
       
       %Plot of Velocity and Sheer Stress across Channel
       fprintf (‘\nAnd now the plots.\n’)
       j = linspace(0,l,l);
       jj= j.*j;
       vf=p *((h*h)-(4.*jj))./(8*vi*l);
       ssf=p.*abs(j)./l;
       plot(j,vf)
       %labels and titles
       title(‘Velocity Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Velocity(cm/s)’)
       %Open up another image for the sheer stress plot
       figure
       plot(j,ssf)
       %title and labels
       title(‘Sheer Stress Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Sheer Stress (dyne/(cm^2))’)
       
   case 6
     fprintf (‘\nOkay great! The value will be calculated once’)
       fprintf (‘\na litte more information is given. Please enter the known’)
       fprintf (‘\nparameters when requested in the proper units.\n’)
       
       %Enter Volumetric Flow Rate
       prompt1=’\nPlease enter volumetric flow rate in (cm^3)/s.\n’;
       q = input(prompt1);
       
       %Enter Width
       prompt2=’\nPlease enter width in centimeters.\n’;
       w = input(prompt2);
       
       %Enter Height
       prompt3=’Please enter height in centimeters.\n’;
       h = input(prompt3);
       
        %Enter Length
       prompt4=’Please enter length in centimeters.\n’;
       l = input(prompt4);
       
       %Enter Delta P
       prompt5=’Please enter Delta P in dyne/(cm^2).\n’;
       p = input(prompt5);
       
       %Time to calculate the missing parameter
       fprintf (‘\nOkay good! Now that all of the known parameters’)
       fprintf (‘\nhave been inputted, we can calculate the Volumetric’)
       fprintf (‘\nFlow Rate.\n’)
       vi=(w*h*h*h*p)/(12*q*l);
       
       %Results Calculations
       vavg = (h * h * p)/(12 * vi * l);
       dh = (4 * w * h)/(2 * (w + h));
       ss = ((h/2) * p)/l;
       re = (d * dh * vavg)/vi;
       el = .06 * re * dh;
       
       %Table of Values
       fprintf (‘\n’)
       fprintf (‘\nHere is the table containing all of the parameters’)
       fprintf (‘\nand the results calculations, along with units.\n’)
       fprintf (‘\n    Results/Parameters     Value     Units’)
       fprintf (‘\n   Volumetric Flow Rate      %f     (cm^3)/s ‘,q)
       fprintf (‘\n         Width               %f        cm ‘,w)
       fprintf (‘\n        Height               %f        cm ‘,h)
       fprintf (‘\n        Length               %f        cm ‘,l)
       fprintf (‘\n        Delta P              %f     dyne/(cm^2) ‘,p)
       fprintf (‘\n       Viscosity             %f      g/(cm*s) ‘,vi)
       fprintf (‘\n    Average Velocity         %f       cm/s ‘,vavg)
       fprintf (‘\n Sheer Stress at the Wall    %f    dyne/(cm^2) ‘,ss)
       fprintf (‘\n     Reynolds Number         %f     unitless ‘,re)
       fprintf (‘\n     Entrance Length         %f        cm \n’,el)
       
       %Plot of Velocity and Sheer Stress across Channel
       fprintf (‘\nAnd now the plots.\n’)
       j = linspace(0,l,l);
       jj= j.*j;
       vf=p *((h*h)-(4.*jj))./(8*vi*l);
       ssf=p.*abs(j)./l;
       plot(j,vf)
       %labels and titles
       title(‘Velocity Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Velocity(cm/s)’)
       %Open up another image for the sheer stress plot
       figure
       plot(j,ssf)
       %title and labels
       title(‘Sheer Stress Across Channel’)
       xlabel(‘Length of Channel (cm)’)
       ylabel(‘Sheer Stress (dyne/(cm^2))’)
       
   otherwise
       fprintf (‘\nInvalid entry. Please restart the program.\n’)
       ans=0;
end