Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creates values of Vr from 0.5 to 3 in steps of (3-0.5)/100

Similar presentations


Presentation on theme: "Creates values of Vr from 0.5 to 3 in steps of (3-0.5)/100"β€” Presentation transcript:

1 Clear command, clears the screen; clears all objects; closes all figures etc.
Creates values of Vr from 0.5 to 3 in steps of (3-0.5)/100 Opens a figure window Y axis limits X axis limits Labels x axis Labels y axis Defines the van der Waals equation as a function of Tr and Vr Calculate Pr using the vdW equation Plots Pr vs. Vr clc; clear all; close all Vr = linspace(0.5,3,100); figure(1); ylim([0 2]) xlim([0.25 3]) xlabel('V_r') ylabel('P_r') Tr = 0.9; Prfunc 8*Tr./(3*Vr - 1) - 3./(Vr.^2); Pr = Prfunc(Vr); plot(Vr,Pr)

2 if Tr < 1 Pr_b = 1.0; vdW_Pr_b = [1 -1/3*(1+8*Tr/Pr_b) 3/Pr_b -1/Pr_b]; Makes sure the temperature is below critical, Tr = T/Tc Starts with a trial value for Pr at which liquid transform to gas Defines a polynomial function to calculate the values of Vr for the trial value of Pr (Pr_b). β‡’ 8 𝑇 π‘Ÿ 3 𝑉 π‘Ÿ βˆ’1 βˆ’ 3 𝑉 π‘Ÿ 2 = 𝑃 π‘Ÿπ‘ β‡’ 8 𝑇 π‘Ÿ 3 𝑉 π‘Ÿ βˆ’1 βˆ’ 3 𝑉 π‘Ÿ 2 βˆ’ 𝑃 π‘Ÿπ‘ =0 β‡’8 𝑇 π‘Ÿ 𝑉 π‘Ÿ 2 βˆ’3 3 𝑉 π‘Ÿ βˆ’1 βˆ’ 𝑃 π‘Ÿπ‘ 3 𝑉 π‘Ÿ βˆ’1 𝑉 π‘Ÿ 2 =0 β‡’8 𝑇 π‘Ÿ 𝑉 π‘Ÿ 2 βˆ’ 9𝑉 π‘Ÿ +3βˆ’3 𝑃 π‘Ÿπ‘ 𝑉 π‘Ÿ 3 + 𝑃 π‘Ÿπ‘ 𝑉 π‘Ÿ 2 =0 β‡’ 𝑉 π‘Ÿ 3 βˆ’ 𝑇 π‘Ÿ 𝑃 π‘Ÿπ‘ 𝑉 π‘Ÿ 𝑃 π‘Ÿπ‘ 𝑉 π‘Ÿ βˆ’ 1 𝑃 π‘Ÿπ‘ =0 The terms in the square brackets are the coefficients of the polynomial.

3 v = sort(roots(vdW_Pr_b));
A1 = (v(2)-v(1))*Pr_b - integral(Prfunc,v(1),v(2)); A2 = integral(Prfunc,v(2),v(3)) - (v(3)-v(2))*Pr_b; Finds the roots of the polynomial and sorts them in increasing order: v(1), v(2), and v(3) Calculates the area enclosed by the line and the vdW curve between v(1) and v(2) and then from v(2) and v(3). (clearer figure later).

4 Z = abs(A1-A2); while Z > vdW_Pr_b = [1 -1/3*(1+8*Tr/Pr_b) 3/Pr_b -1/Pr_b]; v = sort(roots(vdW_Pr_b)); Prfunc 8*Tr./(3*Vr - 1) - 3./(Vr.^2); A1 = (v(2)-v(1))*Pr_b - integral(Prfunc,v(1),v(2)); A2 = integral(Prfunc,v(2),v(3)) - (v(3)-v(2))*Pr_b; Z = abs(A1 - A2); Pr_b = Pr_b ; figure(1); hold off; plot(Vr,Pr) figure(1); hold on; plot([0.5 3],[Pr_b Pr_b],'k--') hold off; end Calculates the difference between the two areas If z > then this loop starts Defines the polynomial in the loop Calculates and sorts the roots Defines vdW equation in the loop Calculates the areas again Calculates the difference Lowers the test values Pr_b by Chooses figure 1 window; new plot will appear, old graph is removed Plots Pr vs. Vr Chooses figure 1window; new plot will appear keeping the old graph Plots the line for Pr_b vs. Vr in a black dashed line Next time a new graph is plotted the old plots will be removed Starts the loop again and checks if the difference between A1 and A2 (Z) > for the new value of Pr_b. Loop stops if Z < i.e A1 ο‚» A2

5 v(1) v(2) v(3) Pr_b (v(2)-v(1))*Pr_b (v(3)-v(2))*Pr_b

6 v(1) v(2) v(3) Pr_b Calculates the area under the vdW curve from v(1) to v(2) and from v(2) to v(3). integral(Prfunc,v(1),v(2)) integral(Prfunc,v(2),v(3))

7 v(1) v(2) v(3) Pr_b Calculates the relevant area for the Maxwell constructions (v(2)-v(1))*Pr_b - integral(Prfunc,v(1),v(2)) integral(Prfunc,v(2),v(3)) - (v(3)-v(2))*Pr_b

8 end A1 A2 Pr_b Ends the if loop Prints A1 and A2 Prints the value of pressure Pr_b which satisfies Maxwell’s condition.


Download ppt "Creates values of Vr from 0.5 to 3 in steps of (3-0.5)/100"

Similar presentations


Ads by Google