%% %Isentropic, Normal shock Relations and Linear Interpolation Formulas %Isentropic Relations %Calculate Total Pressure Over Local Pressure (Pt/Px) FindPtOverPLoc = @(G,MAtPLoc) (1+.5*(G-1)*(MAtPLoc^2))^(G/(G-1)); %Formula to determine Pt/Ploc %Calculate Area/Area_Star FindAOverAStar = @(G,MAtALoc) (1/MAtALoc)*(((2/(G+1))*(1+.5*(G1)*(MAtALoc^2)))^((.5*(G+1))/(G-1))); %Formula to detmerine A/AStar %Calculate Total Temperature Over Local Temperature FindTtOverTLoc = @(G,MAtT1)(1+.5*(G-1)*(MAtT1^2)); %Formula to determine Tt/Tloc %Shock Relations %Calculate M2 FindM2 = @(G,M1) ((1+.5*(G-1)*(M1^2))/(G*(M1^2)-.5*(G-1)))^.5; %Formula to detmerine M2 after the shock %Calculate P2/P1 (pressure relation before and after shock) FindP2OverP1 = @(G,M1) 1+((2*G)/(G+1))*((M1^2)-1); %Formula to detmerine P2/P1(Pressure After Shock/Pressure Before Shock) %Linear Interpolation Scheme %y2 = y1 + (y3-y1)*((x2-x1)/(x3-x1)) LinearInterpolate = @(y1,y3,x1,x2,x3) y1 + (y3-y1)*((x2-x1)/(x3-x1)); %% % inputing the ratios necessary for the problem prompt = 'What is the ratio of exit static pressure to reservoir total pressure? '; PeOverPt1Initial = input(prompt); prompt = 'What is the ratio of the exit area to the throat area? '; AeOverA1Star = input(prompt); %% Properties of air G = 1.4; %Specific heat ratio of air, gamma %% %The throat area is found by dividing Ae by Ae/A1*. Ae = 1 A1Star = 1/AeOverA1Star; % A guess at the LOCATION of the shockwave. Iteration will begin with this % value XShockGuess = 0.01; % Use an iteration scheme to converge onto a final value of Pe/Pt1 % Using the steps below. %% repeat = 1; %Initial condition for Pressure Loop %Initializing arrays for specific outputs Machs = zeros; x = zeros; StaticPressure = zeros; Temperature = zeros; %Initializing variable for Interpolation PeOverPt1Upper = 0; PeOverPt1Lower = 0; ShockLocationUpper = 0; ShockLocationLower = 0; i = 1; %initial i counter %While loop to find Pressure ratio for changing shock locations while repeat == 1 AShock = A1Star + (1-A1Star)*XShockGuess; %Area of shock AoA1star = AShock / A1Star; %Area of Shock / Area of First Throat % First use iteration to find M1 at the guessed shock location, then use the % formula for p1/pt1 %% %Initial values for Secant Method to Find Mach number Mtol = 1; M1a = 1; M1b = 3; %Area Ratio for Lower Mach Number Guess Y1 = FindAOverAStar(G,M1a)- AoA1star; %Secant Method to Find Mach Number while Mtol > .01 %Area Ratio for upper Mach Number Guess Y2 = FindAOverAStar(G,M1b)- AoA1star; %Estimated Mach Number M1next = M1b-(((Y2)*(M1b-M1a))/(Y2-Y1)); %Exchanging of Values M1a = M1b; M1b = M1next; %New Value becomes Old Value Y1 = Y2; %Set Tolerance Mtol = abs(M1b-M1a)/M1a; end %Mach Number Value M1 = M1b; Pt1OverP1 = FindPtOverPLoc(G,M1); %Finds P1/Pt1 at M1 M2 = FindM2(G,M1); %Formula to detmerine M2 after the shock Pt2OverP2 = FindPtOverPLoc(G,M2); %Finds P2/Pt2 at M2 P2OverP1 = FindP2OverP1(G,M1); %Formula to detmerine P2/P1(Pressure After Shock/Pressure Before Shock) Pt2OverPt1 = (Pt2OverP2 / Pt1OverP1) * P2OverP1; %Finds Pt2/Pt1 using pressure ratios % Use formula to calculate A2/A2* from isentropic relations using M2 A2OverA2Star = FindAOverAStar(G,M2); %Formula to detmerine A2/A2Star % Ae/A2* = Ae/A2 * A2/A2* (Ae is 1 and A2 is the same as the shock Area.) AeOverA2Star = 1/(A1Star + ( 1 - A1Star ) * XShockGuess)*A2OverA2Star; %Use Secant Method to Calculate Me using Ae/A2* %% %Initialize Tolerance Value Mtol = 1; %Bounds: Change as needed Mea = .3; Meb = .6; %Area Ratio for Lower Mach Number Guess Y1 = FindAOverAStar(G,Mea)- AeOverA2Star; %Secant Method to Find Mach Number while Mtol > .01 %Area Ratio for upper Mach Number Guess Y2 = FindAOverAStar(G,Meb)- AeOverA2Star; %Estimated Mach Number Menext = Meb-(((Y2)*(Meb-Mea))/(Y2-Y1)); %Exchanging of Values Mea = Meb; Meb = Menext; %New Value becomes Old Value Y1 = Y2; %Set Tolerance Mtol = abs(Meb-Mea)/Mea; end %Mach Number at the Exit Me = Meb; % Use Me to find Pe/Pt2 with isentropic formulas. PeOverPt2 = 1/FindPtOverPLoc(G,Me); %Formula to detmerine Pe/Pt2 %PeOverPt1new = PeOverPt2 * Pt2OverPt1 if (PeOverPt2 * Pt2OverPt1) < PeOverPt1Initial PeOverPt1Upper = PeOverPt2 * Pt2OverPt1; ShockLocationUpper = XShockGuess; repeat = 0; else PeOverPt1Lower = PeOverPt2 * Pt2OverPt1; ShockLocationLower = XShockGuess; repeat = 1; end %Fill Arrays for Specified Variables Machs(i) = M1; x(i) = XShockGuess; StaticPressure(i)=1/FindPtOverPLoc(G,M1); Temperature(i) = 1/FindTtOverTLoc(G,M1); %Increment Shock Guess Location XShockGuess = XShockGuess + 0.001; %Increment i counter i = i+1; end %% % To find M between shock and exit. A2Star = AShock/A2OverA2Star; %AShock = A2 X = XShockGuess; %Location after the shock %Loop to find Specified Values after Shock based on Mach Number while X <= 1 %Area of Linearly Expanding Nozzle A = A1Star + ( 1 - A1Star ) * X; AOverA2Star = A/A2Star; %Area Ratio after shock %% Secant Method Again %Uses different bounds Mtol = 1; Ma = .2; Mb = .7; Y1 = FindAOverAStar(G,Ma)- AOverA2Star; while Mtol > .01 Y2 = FindAOverAStar(G,Mb)- AOverA2Star; Mnext = Mb-(((Y2)*(Mb-Ma))/(Y2-Y1)); Ma = Mb; Mb = Mnext; Y1 = Y2; Mtol = abs(Mb-Ma)/Ma; end %% Continue to Fill Arrays for Specified Variables Machs(i) = Mb; x(i) = X; StaticPressure(i) = Pt2OverPt1/FindPtOverPLoc(G,Mb); Temperature(i) = 1/FindTtOverTLoc(G,Mb); % i % X i counter = i + 1; Increment Location in Nozzle = X + .001; end %% %Linear Interpolation Check to find shock location ShockLocation = LinearInterpolate(ShockLocationLower,ShockLocationUpper,PeOverPt1Upper,PeOver Pt1Initial,PeOverPt1Lower); %display shock location disp('Shock Location = '); disp(ShockLocation); %% %Plots figure (1) subplot(3,1,1) plot(x,Machs) title('Mach Number vs Distance Downstream'); xlabel('Distance Downstream, x'); ylabel('Mach Number'); subplot(3,1,2) plot(x,StaticPressure) title('Local Static Pressure/Reservoir Total Pressure vs Distance Downstream'); xlabel('Distance Downstream, x'); ylabel('P Static/Pt1'); subplot(3,1,3) plot(x,Temperature) title('Local Temperature/ Total Temperature vs Distance Downstream'); xlabel('Distance Downstream, x'); ylabel('T local/ T total');