Professional Documents
Culture Documents
Codes
Codes
% Given data
thickness = 0.5 / 100; % in meters (0.5 cm converted to meters)
thickness_1cm = 1 / 100; % in meters (1 cm converted to meters)
surface_temp_inner = 10; % in °C
surface_temp_outer = 3; % in °C
thermal_conductivity = 0.78; % in W/m·°C
time_duration = 5 * 3600; % in seconds (5 hours converted to seconds)
% Calculate heat transfer rate and total heat loss for 1 cm thickness
heat_transfer_rate_1cm = thermal_conductivity * (surface_temp_inner -
surface_temp_outer) / thickness_1cm;
heat_loss_1cm = heat_transfer_rate_1cm * time_duration / 1000; % in kJ
for i = 1:length(thickness_range)
heat_transfer_rate_i = thermal_conductivity * (surface_temp_inner -
surface_temp_outer) / thickness_range(i);
heat_loss_range(i) = heat_transfer_rate_i * time_duration / 1000; % in kJ
end
figure;
plot(thickness_range * 100, heat_loss_range, 'b', 'LineWidth', 2);
xlabel('Glass Thickness (cm)');
ylabel('Heat Loss (kJ)');
title('Effect of Glass Thickness on Heat Loss');
grid on;
2)
% Given data
diameter = 5 / 100; % in meters (5 cm converted to meters)
surface_temp = 70; % in °C
surrounding_temp = 20; % in °C
convection_coefficient_range = linspace(5, 30, 100); % Range of convection heat
transfer coefficient (W/m2 · °C)
emissivity_range = [0.1, 0.5, 0.8, 1]; % Surface emissivity values
% Stefan-Boltzmann constant
sigma = 5.67e-8; % in W/m2 · K4
% Initialize array to store heat transfer rates
heat_transfer_rates = zeros(length(emissivity_range),
length(convection_coefficient_range));
% Plotting the effect of convection heat transfer coefficient on heat transfer rate
figure;
plot(convection_coefficient_range, heat_transfer_rates, 'LineWidth', 2);
xlabel('Convection Heat Transfer Coefficient (W/m^2 · °C)');
ylabel('Rate of Heat Transfer (W)');
title('Effect of Convection Heat Transfer Coefficient on Heat Transfer Rate');
legend('Emissivity = 0.1', 'Emissivity = 0.5', 'Emissivity = 0.8', 'Emissivity =
1');
grid on;
3)
% Given data
V_refrigerant_initial = 0.01; % Initial volume of refrigerant-134a (m^3)
T_final = 20 + 273.15; % Final temperature of the refrigerant (K)
P_final = 400e3; % Final pressure of the refrigerant (Pa)
% Constants
R_specific = 188.93; % Specific gas constant for refrigerant-134a (J/kg·K)
% Calculate specific volume of refrigerant at final state using the ideal gas
law
v_specific_final = R_specific * T_final / P_final;
4)
% Given data
V1 = 0.5; % Volume of tank 1 (m^3)
V2 = 0.5; % Volume of tank 2 (m^3)
T1 = 20 + 273.15; % Initial temperature of tank 1 (K)
T2 = 30 + 273.15; % Initial temperature of tank 2 (K)
P1 = 600e3; % Initial pressure of tank 1 (Pa)
P2 = 150e3; % Initial pressure of tank 2 (Pa)
T_surroundings_range = linspace(-10 + 273.15, 30 + 273.15, 100); % Surroundings
temperature range (K)
% Constants
R_specific = 8.314; % Specific gas constant for hydrogen (J/mol·K)
Molar_mass = 2.016; % Molar mass of hydrogen (g/mol)
% Given data
P = 10e6; % Pressure (Pa)
T = 400 + 273.15; % Temperature (K)
% Constants
R = 8.314; % Universal gas constant (J/mol·K)
Molar_mass = 18.01528; % Molar mass of water (g/mol)
% Display results
disp('(a) Ideal Gas Equation:');
disp(['Specific volume: ', num2str(v_ideal_gas), ' m^3/kg']);
disp(['Percent Error: ', num2str(error_ideal_gas), '%']);
disp('(b) Generalized Compressibility Chart:');
disp(['Specific volume: ', num2str(v_generalized_compressibility), ' m^3/kg']);
disp(['Percent Error: ', num2str(error_generalized_compressibility), '%']);
disp('(c) Steam Tables:');
disp(['Specific volume: ', num2str(v_steam_tables), ' m^3/kg']);
for i = 1:length(T_range)
T_temp = T_range(i) + 273.15; % Convert temperature to Kelvin
% Calculate specific volume using steam tables
% For simplicity, we assume a specific volume based on the properties of
superheated steam
% at 10 MPa and the current temperature obtained from steam tables
v_steam_temp = 0.0428; % m^3/kg (example value)
% Calculate percent error for ideal gas approximation
v_ideal_gas_temp = R * T_temp / P; % Specific volume using ideal gas equation
v_percent_error(i) = abs(v_steam_temp - v_ideal_gas_temp) / v_steam_temp * 100;
% Percent error
end
6)
% Given data
diameter_range = linspace(5, 15, 100); % Balloon diameter range (m)
T = 20 + 273.15; % Temperature (K)
P_values = [100e3, 200e3]; % Pressure values (Pa)
Molar_mass = 4.002602; % Molar mass of helium (g/mol)
% Constants
R = 8.314; % Universal gas constant (J/mol·K)
% Constants
R = 8.314; % Universal gas constant in J/(mol*K)
v = 1; % Specific volume in m^3
m = 2.841; % Mass of steam in kg
P_range = 0.1:0.1:1; % Pressure range in MPa
figure;
plot(P_range, percent_error, 'LineWidth', 2);
xlabel('Pressure (MPa)');
ylabel('Percent Error (%)');
title('Percent Error in Ideal Gas Approximation vs Pressure');
grid on;
8)
% Given data
V_initial = 200; % Initial volume (L)
T_initial = 20; % Initial temperature (°C)
T_final = 70; % Final temperature (°C)
P_range = linspace(400, 1200, 100); % Pressure range (kPa)
% Constants
R_specific = 0.18893; % Specific gas constant for refrigerant-134a (kJ/kg·K)
Molar_mass = 102.03; % Molar mass of refrigerant-134a (g/mol)
% Calculate initial specific volume using ideal gas law for saturated liquid
v_initial = R_specific * T_initial_K / P;
% Calculate final specific volume using ideal gas law for superheated vapor
v_final = R_specific * T_final_K / P;
% Calculate work done using area under the curve (trapezoidal rule)
work_done(i) = (v_final - v_initial) * P * 1000; % Convert from kJ to J
end
9)
% Given data
m_water = 50; % Mass of water (kg)
P_initial = 250e3; % Initial pressure (Pa)
T_initial = 25 + 273.15; % Initial temperature (K)
A_piston = 0.1; % Cross-sectional area of the piston (m^2)
V_final_1 = 0.2; % Final volume after reaching the spring (m^3)
V_final_2 = V_final_1 + 0.2; % Final volume after rising 20 cm more (m^3)
k_spring_range = linspace(50e3, 500e3, 100); % Spring constant range (N/m)
delta_x = 0.2; % Displacement after reaching the spring (m)
delta_x_additional = 0.2; % Additional displacement (m)
% Constants
R_specific = 8.314; % Specific gas constant for water (J/mol·K)
Molar_mass = 18.01528; % Molar mass of water (g/mol)
% Calculate final force exerted by the piston after reaching the spring
F_final = k_spring * delta_x;
subplot(2,1,2);
plot(k_spring_range / 1e3, boundary_work / 1e3, 'LineWidth', 2);
xlabel('Spring Constant (kN/m)');
ylabel('Boundary Work Done (kJ)');
title('Effect of Spring Constant on Boundary Work Done');
grid on;
10)
% Given data
P_in = 300e3; % Inlet pressure (Pa)
T_in = 200 + 273.15; % Inlet temperature (K)
V_in = 30; % Inlet velocity (m/s)
P_out = 100e3; % Outlet pressure (Pa)
V_out = 180; % Outlet velocity (m/s)
A_in = 80 / 1e4; % Inlet area (m^2)
% Constants
gamma = 1.4; % Specific heat ratio for air
% (a) Calculate mass flow rate through the nozzle using mass flow rate equation
rho_in = P_in / (287 * T_in); % Inlet density (kg/m^3)
m_dot = rho_in * V_in * A_in; % Mass flow rate (kg/s)
% Print results
fprintf('(a) Mass flow rate: %.4f kg/s\n', m_dot);
fprintf('(b) Exit temperature: %.2f K\n', T_out);
fprintf('(c) Exit area: %.4f m^2\n', A_out);
% Effect of inlet area on mass flow rate, exit temperature, and exit area
A_in_range = linspace(50 / 1e4, 150 / 1e4, 100); % Inlet area range (m^2)
subplot(3,1,2);
plot(A_in_range * 1e4, T_out_range, 'LineWidth', 2);
xlabel('Inlet Area (cm^2)');
ylabel('Exit Temperature (K)');
title('Effect of Inlet Area on Exit Temperature');
grid on;
subplot(3,1,3);
plot(A_in_range * 1e4, A_out_range * 1e4, 'LineWidth', 2);
xlabel('Inlet Area (cm^2)');
ylabel('Exit Area (cm^2)');
title('Effect of Inlet Area on Exit Area');
grid on;
11)
% Given data
P_in = 10e6; % Inlet pressure (Pa)
T_in = 450 + 273.15; % Inlet temperature (K)
V_in = 80; % Inlet velocity (m/s)
P_out = 10e3; % Outlet pressure (Pa)
x_out = 0.92; % Quality of steam at outlet
V_out = 50; % Outlet velocity (m/s)
m_dot = 12; % Mass flow rate (kg/s)
% Constants
R_specific = 0.4615; % Specific gas constant for steam (kJ/kg·K)
gamma = 1.4; % Specific heat ratio for steam
% Print results
fprintf('(a) Change in Kinetic Energy: %.2f kJ/s\n', delta_KE);
fprintf('(b) Power Output: %.2f kW\n', W_out);
fprintf('(c) Turbine Inlet Area: %.4f m^2\n', A_in);
12)
% Given data
T_source_range = linspace(300, 1000, 100); % Source temperature range (°C)
T_sink_range = [0, 25, 50]; % Sink temperature range (°C)
Q_in = 1200 * 60; % Heat supplied to the engine (kJ/min) converted to kJ/s
% Constants
T_0 = 273.15; % Absolute zero temperature (K)
% Store results
power_produced(i, j) = max_power_output;
cycle_efficiency(i, j) = efficiency_carnot;
end
end
13)
% Given data
m_steam = 0.0103; % Mass of steam (kg)
W_net_range = linspace(15, 25, 100); % Net work output range (kJ)
% Constants
R_specific = 0.4615; % Specific gas constant for steam (kJ/kg·K)
% Calculate maximum absolute temperature (Tw) and minimum absolute temperature (Tc)
Tw = 2 * 273.15; % Max absolute temperature (K)
Tc = 273.15; % Min absolute temperature (K)
% Plot temperature of steam during heat rejection process against net work output
plot(W_net_range, T_reject, 'LineWidth', 2);
xlabel('Net Work Output (kJ)');
ylabel('Temperature during Heat Rejection (°C)');
title('Effect of Net Work Output on Steam Temperature during Heat Rejection');
grid on;
14)
% Given data
Q_added_range = [500, 900, 1300]; % Heat added to the working fluid (kJ)
T_source_range = linspace(100, 1000, 100); % Source temperature range (°C)
% Constants
R_specific = 0.287; % Specific gas constant for air (kJ/kg·K)
% Plot entropy changes against source temperature for different heat added
figure;
subplot(3,1,1);
plot(T_source_range, entropy_change_fluid, 'LineWidth', 2);
xlabel('Source Temperature (°C)');
ylabel('Entropy Change of Working Fluid (kJ/K)');
title('Effect of Source Temperature on Entropy Change of Working Fluid');
legend('Q = 500 kJ', 'Q = 900 kJ', 'Q = 1300 kJ');
grid on;
subplot(3,1,2);
plot(T_source_range, entropy_change_source, 'LineWidth', 2);
xlabel('Source Temperature (°C)');
ylabel('Entropy Change of Source (kJ/K)');
title('Effect of Source Temperature on Entropy Change of Source');
legend('Q = 500 kJ', 'Q = 900 kJ', 'Q = 1300 kJ');
grid on;
subplot(3,1,3);
plot(T_source_range, total_entropy_change, 'LineWidth', 2);
xlabel('Source Temperature (°C)');
ylabel('Total Entropy Change (kJ/K)');
title('Effect of Source Temperature on Total Entropy Change');
legend('Q = 500 kJ', 'Q = 900 kJ', 'Q = 1300 kJ');
grid on;