CodeCodeCode

ENRG132: HW02 - hw02_pvtplot_name

Mar 30th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.32 KB | None | 0 0
  1. % --- INPUTS ---
  2. %defines constant n (number of moles of gas) with units moles
  3. n = 2;      
  4. %defines constant a (gas characteristic) with units (L^2*bar)/mol^2
  5. a = 5.536;  
  6. %defines constant b (gas characteristic) with units L/mol
  7. b = 0.03049;    
  8. %defines constant R (ideal gas constant) with units (L*bar)/(K*mol)
  9. R = 0.08314472;
  10.  
  11. %Part (a)
  12. %defines P_a (pressure) as 10 values from 0 to 400 bars
  13. P_a = linspace(0, 400, 10);
  14. %defines V_a (volume) as 1 liter
  15. V_a = 1;
  16.    
  17. %Part (b)
  18. %defines P_b (pressure) as 220 bars
  19. P_b = 220;
  20. %defines V_b (volume) as 10 values from 0.1 to 10.0 liters
  21. V_b = linspace(0.1, 10.0, 10);
  22.  
  23. %Part (c)
  24. %defines P_c (pressure) as 10 values from 0 to 400 bars
  25. P_c = linspace(0, 400, 10);
  26. %defines V_c (volume) as 10 values from 0.1 to 10.0 liters
  27. V_c = linspace(0.1, 10.0, 10);
  28.    
  29. % --- CALCULATIONS ---
  30. %Part (a)
  31. %calculates T_a (temperature) values based on Part (a) data
  32. T_a = ((P_a + (n^2 * a) / (V_a^2)) * (V_a - n * b)) / (n * R);
  33.    
  34. %Part (b)
  35. %calculates T_b (temperature) values based on Part (b) data
  36. T_b = ((P_b + (n^2 * a) ./ (V_b.^2)) .* (V_b - n * b)) ./ (n * R);
  37.  
  38. %Part (c)
  39. %calculates T_c (temperature) values based on Part (c) data
  40. T_c = ((P_c + (n^2 * a) ./ (V_c.^2)) .* (V_c - n * b)) ./ (n * R);
  41.  
  42. % --- OUTPUTS ----
  43. %Part (a)
  44. %T_a =
  45. %
  46. %1.0e+003 *
  47. %
  48. %Columns 1 through 7
  49. %
  50. %0.1250    0.3760    0.6270    0.8780    1.1289    1.3799    1.6309
  51. %
  52. %Columns 8 through 10
  53. %
  54. %1.8819    2.1328    2.3838
  55.  
  56. %plots T_a (temperature) as a function of P_a (pressure)on figure 1
  57. figure(1);
  58. plot(P_a, T_a);
  59. xlabel('Pressure (Bars)');
  60. ylabel('Temperature (Kelvin)');
  61. title('Temperature (Kelvin) as a Function of Pressure (Bars)');
  62. grid;
  63.    
  64.  
  65. %Part (b)
  66. %T_b =
  67. %
  68. %1.0e+004 *
  69. %
  70. %Columns 1 through 7
  71. %
  72. %0.0571    0.1612    0.3019    0.4456    0.5902    0.7352    0.8803
  73. %
  74. %Columns 8 through 10
  75. %
  76. %1.0256    1.1709    1.3163
  77.        
  78. %plots T_b (temperature) as a function of V_b (volume)on figure 2
  79. figure(2);
  80. plot(V_b, T_b);
  81. xlabel('Volume (Liters)');
  82. ylabel('Temperature (Kelvin)');
  83. title('Temperature (Kelvin) as a Function of Volume (Liters)');
  84. grid;
  85.  
  86.  
  87. %Part (c)
  88. %T_c =
  89. %
  90. %  1.0e+004 *
  91. %
  92. %  Columns 1 through 7
  93. %
  94. %    0.0520    0.0410    0.1253    0.2716    0.4775    0.7426    1.0666
  95. %
  96. %  Columns 8 through 10
  97. %
  98. %    1.4496    1.8914    2.3921
Advertisement
Add Comment
Please, Sign In to add comment