Codes
Codes
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)
% Constants
sigma = 5.67e-8; % Stefan-Boltzmann constant (W/m^2 · K^4)
% Plotting
figure;
plot(h_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)
% Constants
R = 8.314; % Gas constant in J/(mol*K)
% Initial conditions
V1 = 0.5; % Volume of tank 1 in m^3
T1 = 20 + 273.15; % Temperature of tank 1 in K
P1 = 600 * 1000; % Pressure of tank 1 in Pa
V2 = 0.5; % Volume of tank 2 in m^3
T2 = 30 + 273.15; % Temperature of tank 2 in K
P2 = 150 * 1000; % Pressure of tank 2 in Pa
T_surroundings = -10:1:30; % Surroundings temperature range in °C
T_surroundings = T_surroundings + 273.15; % Convert to Kelvin
for i = 1:length(T_surroundings)
% Calculate final equilibrium pressure
T_sur = T_surroundings(i);
n1 = (P1*V1)/(R*T1); % moles of gas in tank 1
n2 = (P2*V2)/(R*T2); % moles of gas in tank 2
n_total = n1 + n2; % total moles of gas
V_total = V1 + V2; % total volume
T_final = (T1*n1*T1 + T2*n2*T2 + T_sur*n_total)/(n1*T1 + n2*T2 + n_total); %
final temperature
final_pressure(i) = (n_total*R*T_final)/V_total; % final pressure
end
% Plot
figure;
plot(final_pressure / 1000, T_surroundings, 'LineWidth', 2);
xlabel('Final Pressure (kPa)');
ylabel('Surroundings Temperature (K)');
title('Final Pressure vs Surroundings Temperature');
grid on;
5)
% Given data
P = 10e6; % Pressure (Pa)
T = 400 + 273.15; % Temperature (K)
% Constants
R = 8.314; % Universal gas constant (J/mol·K)
% Calculate percent error for ideal gas approximation using steam tables
T_range = 325:25:600; % Temperature range (°C)
v_steam_tables = 0.0428; % Specific volume at 10 MPa and 400°C (m^3/kg)
v_percent_error = abs(v_steam_tables - R * (T_range + 273.15) / P) / v_steam_tables
* 100;
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)
7)
% 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
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; P_initial = 250e3; T_initial = 25 + 273.15; A_piston = 0.1; V_final_1
= 0.2; V_final_2 = V_final_1 + 0.2;
k_spring_range = linspace(50e3, 500e3, 100); delta_x = 0.2; delta_x_additional =
0.2;
% Constants
R_specific = 8.314; Molar_mass = 18.01528;
% Initialize arrays
[P_final, boundary_work] = deal(zeros(size(k_spring_range)));
% 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)
Not done
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
% Plot power produced and cycle efficiency against source temperature
figure;
subplot(2,1,1);
plot(T_source_range, power_produced, 'LineWidth', 2);
xlabel('Source Temperature (°C)');
ylabel('Power Produced (W)');
title('Effect of Source Temperature on Power Produced');
legend('Sink Temp: 0°C', 'Sink Temp: 25°C', 'Sink Temp: 50°C');
grid on;
subplot(2,1,2);
plot(T_source_range, cycle_efficiency, 'LineWidth', 2);
xlabel('Source Temperature (°C)');
ylabel('Cycle Efficiency');
title('Effect of Source Temperature on Cycle Efficiency');
legend('Sink Temp: 0°C', 'Sink Temp: 25°C', 'Sink Temp: 50°C');
grid on;
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;
for i = 1:length(Q_added_range)
subplot(3,1,i);
plot(T_source_range, entropy_change_fluid(:, i), 'LineWidth', 2);
hold on;
plot(T_source_range, entropy_change_source(:, i), 'LineWidth', 2);
plot(T_source_range, total_entropy_change(:, i), 'LineWidth', 2);
hold off;
xlabel('Source Temperature (°C)');
ylabel('Entropy Change (kJ/K)');
title(sprintf('Effect of Source Temperature on Entropy Change (Q = %d kJ)',
Q_added_range(i)));
legend('Working Fluid', 'Source', 'Total');
grid on;
end
15)
% Given data
m_aluminum = 20; % Mass of aluminum block (kg)
T_aluminum_initial = 200 + 273.15; % Initial temperature of aluminum block (K)
m_iron_range = 1:10; % Range of mass of iron block (kg)
T_iron_initial = 100 + 273.15; % Initial temperature of iron block (K)
m_total = m_aluminum + m_iron_range; % Total mass of both blocks (kg)
% Constants
C_aluminum = 0.903; % Specific heat capacity of aluminum (kJ/kg·K)
C_iron = 0.449; % Specific heat capacity of iron (kJ/kg·K)
% Plot equilibrium temperature and total entropy change against iron mass
figure;
subplot(2,1,1);
plot(m_iron_range, T_final, 'LineWidth', 2);
xlabel('Mass of Iron Block (kg)');
ylabel('Equilibrium Temperature (K)');
title('Effect of Iron Mass on Equilibrium Temperature');
grid on;
subplot(2,1,2);
plot(m_iron_range, delta_S_total, 'LineWidth', 2);
xlabel('Mass of Iron Block (kg)');
ylabel('Total Entropy Change (kJ/K)');
title('Effect of Iron Mass on Total Entropy Change');
grid on;