The follow code was create to calculate the time to increase the temperature, but when I run it the result is infinite. Anyone can help me?
Below are the tow functions used to calculate the time to increase the temp. according to the inputs: L1, L2, L3 and heat+power. The initial values were: 0.05m; 0.1 m; 0.05m and 500W respectively. But with any other values the result returns the same: inifinite seconds! I need the results in terms of plotting.
function time_to_increase_temperature = calculate_time_to_increase_temperature( …
rho_concrete, rho_air, k_concrete, k_air, ~, cp_concrete, …
cp_air, T_initial, T_surface, L1, L2, L3, volume_P1_P3, ~, …
Nx, Nt, delta_T, heat_power)
% Calculate total thickness
total_thickness = L1 + L2 + L3;
% Thermal diffusivities
alpha_concrete = k_concrete / (rho_concrete * cp_concrete); % m²/s
alpha_air = k_air / (rho_air * cp_air); % m²/s
% Discretization parameters
dx = total_thickness / Nx; % Spatial step size
dt = 6 / Nt; % Time step size
% Preallocate temperature arrays
T = T_initial * ones(Nx, 1);
T_new = T;
% Define material properties at each point
len_P1 = round(Nx * L1 / total_thickness); % Length of concrete layer P1
len_P2 = round(Nx * L2 / total_thickness); % Length of air layer P2
len_P3 = Nx – len_P1 – len_P2; % Length of concrete layer P3
% Ensure len_P3 is correctly adjusted if rounding caused any issues
if len_P1 + len_P2 + len_P3 ~= Nx
len_P3 = Nx – len_P1 – len_P2;
end
% Preallocate material array
material = zeros(Nx, 1);
material(1:len_P1) = alpha_concrete;
material(len_P1+1:len_P1+len_P2) = alpha_air;
material(len_P1+len_P2+1:Nx) = alpha_concrete;
time_to_increase_temperature = inf; % Initialize to store time to increase temperature
% Calculate heat input per spatial point
heat_input_per_point = heat_power * dt / (rho_concrete * cp_concrete * volume_P1_P3 / Nx);
% Time integration using Finite Difference Method (FDM)
time = 0; % Initialize time
for n = 1:Nt
for i = 2:Nx-1
T_new(i) = T(i) + material(i) * dt / dx^2 * (T(i+1) – 2*T(i) + T(i-1));
end
% Boundary conditions
T_new(1) = T(1) + alpha_concrete * dt / dx^2 * (T(2) – T(1)) + heat_input_per_point * (T_surface – T(1));
T_new(Nx) = T(Nx-1);
% Update temperature
T = T_new;
time = time + dt;
% Check if the temperature at the right side of P3 reaches T_initial + delta_T
if T(Nx) >= T_initial + delta_T
time_to_increase_temperature = time;
break;
end
end
% Return the time to increase temperature by 1 K at the right side of P3
end
Function main_process:
function main_process()
% Parameters with fixed values
rho_concrete = 2500; % kg/m³
rho_air = 1293; % kg/m³
k_concrete = 1.35; % W/(m·K)
k_air = 0.024; % W/(m·K) assuming typical value for air
cp_concrete = 0.92 * 1000; % J/(kg·K)
cp_air = 1.005 * 1000; % J/(kg·K)
T_initial = 300; % Initial temperature in K
T_surface = 411; % Surface temperature in K
volume_P1_P3 = 0.00488; % Volume of each concrete plate in m³
Nx = 100; % Number of spatial points
Nt = 1000; % Number of time steps
delta_T = 1; % Temperature increase in K
% Prompt the user for specific input parameters
L1 = input(‘Enter the thickness of the first concrete layer (m): ‘);
L2 = input(‘Enter the thickness of the air layer (m): ‘);
L3 = input(‘Enter the thickness of the second concrete layer (m): ‘);
heat_power = input(‘Enter the heat power (W): ‘);
% Call the function
time_to_increase_temperature = calculate_time_to_increase_temperature( …
rho_concrete, rho_air, k_concrete, k_air, [], cp_concrete, …
cp_air, T_initial, T_surface, L1, L2, L3, volume_P1_P3, [], …
Nx, Nt, delta_T, heat_power);
% Display the result
fprintf(‘Time to increase temperature by 1 K at the right side of P3: %.2f secondsn’, time_to_increase_temperature);
% Plot the result
total_thickness = L1 + L2 + L3;
x = linspace(0, total_thickness, Nx); % Spatial points
y = linspace(0, time_to_increase_temperature, Nx); % Temporal points for plotting
plot(x, y, ‘DisplayName’, ‘Time to Increase Temperature by 1 K’);
xlabel(‘Position (m)’);
ylabel(‘Time (s)’);
legend(‘show’);
title(‘Time to Increase Temperature by 1 K at the right side of P3’);
endBelow are the tow functions used to calculate the time to increase the temp. according to the inputs: L1, L2, L3 and heat+power. The initial values were: 0.05m; 0.1 m; 0.05m and 500W respectively. But with any other values the result returns the same: inifinite seconds! I need the results in terms of plotting.
function time_to_increase_temperature = calculate_time_to_increase_temperature( …
rho_concrete, rho_air, k_concrete, k_air, ~, cp_concrete, …
cp_air, T_initial, T_surface, L1, L2, L3, volume_P1_P3, ~, …
Nx, Nt, delta_T, heat_power)
% Calculate total thickness
total_thickness = L1 + L2 + L3;
% Thermal diffusivities
alpha_concrete = k_concrete / (rho_concrete * cp_concrete); % m²/s
alpha_air = k_air / (rho_air * cp_air); % m²/s
% Discretization parameters
dx = total_thickness / Nx; % Spatial step size
dt = 6 / Nt; % Time step size
% Preallocate temperature arrays
T = T_initial * ones(Nx, 1);
T_new = T;
% Define material properties at each point
len_P1 = round(Nx * L1 / total_thickness); % Length of concrete layer P1
len_P2 = round(Nx * L2 / total_thickness); % Length of air layer P2
len_P3 = Nx – len_P1 – len_P2; % Length of concrete layer P3
% Ensure len_P3 is correctly adjusted if rounding caused any issues
if len_P1 + len_P2 + len_P3 ~= Nx
len_P3 = Nx – len_P1 – len_P2;
end
% Preallocate material array
material = zeros(Nx, 1);
material(1:len_P1) = alpha_concrete;
material(len_P1+1:len_P1+len_P2) = alpha_air;
material(len_P1+len_P2+1:Nx) = alpha_concrete;
time_to_increase_temperature = inf; % Initialize to store time to increase temperature
% Calculate heat input per spatial point
heat_input_per_point = heat_power * dt / (rho_concrete * cp_concrete * volume_P1_P3 / Nx);
% Time integration using Finite Difference Method (FDM)
time = 0; % Initialize time
for n = 1:Nt
for i = 2:Nx-1
T_new(i) = T(i) + material(i) * dt / dx^2 * (T(i+1) – 2*T(i) + T(i-1));
end
% Boundary conditions
T_new(1) = T(1) + alpha_concrete * dt / dx^2 * (T(2) – T(1)) + heat_input_per_point * (T_surface – T(1));
T_new(Nx) = T(Nx-1);
% Update temperature
T = T_new;
time = time + dt;
% Check if the temperature at the right side of P3 reaches T_initial + delta_T
if T(Nx) >= T_initial + delta_T
time_to_increase_temperature = time;
break;
end
end
% Return the time to increase temperature by 1 K at the right side of P3
end
Function main_process:
function main_process()
% Parameters with fixed values
rho_concrete = 2500; % kg/m³
rho_air = 1293; % kg/m³
k_concrete = 1.35; % W/(m·K)
k_air = 0.024; % W/(m·K) assuming typical value for air
cp_concrete = 0.92 * 1000; % J/(kg·K)
cp_air = 1.005 * 1000; % J/(kg·K)
T_initial = 300; % Initial temperature in K
T_surface = 411; % Surface temperature in K
volume_P1_P3 = 0.00488; % Volume of each concrete plate in m³
Nx = 100; % Number of spatial points
Nt = 1000; % Number of time steps
delta_T = 1; % Temperature increase in K
% Prompt the user for specific input parameters
L1 = input(‘Enter the thickness of the first concrete layer (m): ‘);
L2 = input(‘Enter the thickness of the air layer (m): ‘);
L3 = input(‘Enter the thickness of the second concrete layer (m): ‘);
heat_power = input(‘Enter the heat power (W): ‘);
% Call the function
time_to_increase_temperature = calculate_time_to_increase_temperature( …
rho_concrete, rho_air, k_concrete, k_air, [], cp_concrete, …
cp_air, T_initial, T_surface, L1, L2, L3, volume_P1_P3, [], …
Nx, Nt, delta_T, heat_power);
% Display the result
fprintf(‘Time to increase temperature by 1 K at the right side of P3: %.2f secondsn’, time_to_increase_temperature);
% Plot the result
total_thickness = L1 + L2 + L3;
x = linspace(0, total_thickness, Nx); % Spatial points
y = linspace(0, time_to_increase_temperature, Nx); % Temporal points for plotting
plot(x, y, ‘DisplayName’, ‘Time to Increase Temperature by 1 K’);
xlabel(‘Position (m)’);
ylabel(‘Time (s)’);
legend(‘show’);
title(‘Time to Increase Temperature by 1 K at the right side of P3’);
end Below are the tow functions used to calculate the time to increase the temp. according to the inputs: L1, L2, L3 and heat+power. The initial values were: 0.05m; 0.1 m; 0.05m and 500W respectively. But with any other values the result returns the same: inifinite seconds! I need the results in terms of plotting.
function time_to_increase_temperature = calculate_time_to_increase_temperature( …
rho_concrete, rho_air, k_concrete, k_air, ~, cp_concrete, …
cp_air, T_initial, T_surface, L1, L2, L3, volume_P1_P3, ~, …
Nx, Nt, delta_T, heat_power)
% Calculate total thickness
total_thickness = L1 + L2 + L3;
% Thermal diffusivities
alpha_concrete = k_concrete / (rho_concrete * cp_concrete); % m²/s
alpha_air = k_air / (rho_air * cp_air); % m²/s
% Discretization parameters
dx = total_thickness / Nx; % Spatial step size
dt = 6 / Nt; % Time step size
% Preallocate temperature arrays
T = T_initial * ones(Nx, 1);
T_new = T;
% Define material properties at each point
len_P1 = round(Nx * L1 / total_thickness); % Length of concrete layer P1
len_P2 = round(Nx * L2 / total_thickness); % Length of air layer P2
len_P3 = Nx – len_P1 – len_P2; % Length of concrete layer P3
% Ensure len_P3 is correctly adjusted if rounding caused any issues
if len_P1 + len_P2 + len_P3 ~= Nx
len_P3 = Nx – len_P1 – len_P2;
end
% Preallocate material array
material = zeros(Nx, 1);
material(1:len_P1) = alpha_concrete;
material(len_P1+1:len_P1+len_P2) = alpha_air;
material(len_P1+len_P2+1:Nx) = alpha_concrete;
time_to_increase_temperature = inf; % Initialize to store time to increase temperature
% Calculate heat input per spatial point
heat_input_per_point = heat_power * dt / (rho_concrete * cp_concrete * volume_P1_P3 / Nx);
% Time integration using Finite Difference Method (FDM)
time = 0; % Initialize time
for n = 1:Nt
for i = 2:Nx-1
T_new(i) = T(i) + material(i) * dt / dx^2 * (T(i+1) – 2*T(i) + T(i-1));
end
% Boundary conditions
T_new(1) = T(1) + alpha_concrete * dt / dx^2 * (T(2) – T(1)) + heat_input_per_point * (T_surface – T(1));
T_new(Nx) = T(Nx-1);
% Update temperature
T = T_new;
time = time + dt;
% Check if the temperature at the right side of P3 reaches T_initial + delta_T
if T(Nx) >= T_initial + delta_T
time_to_increase_temperature = time;
break;
end
end
% Return the time to increase temperature by 1 K at the right side of P3
end
Function main_process:
function main_process()
% Parameters with fixed values
rho_concrete = 2500; % kg/m³
rho_air = 1293; % kg/m³
k_concrete = 1.35; % W/(m·K)
k_air = 0.024; % W/(m·K) assuming typical value for air
cp_concrete = 0.92 * 1000; % J/(kg·K)
cp_air = 1.005 * 1000; % J/(kg·K)
T_initial = 300; % Initial temperature in K
T_surface = 411; % Surface temperature in K
volume_P1_P3 = 0.00488; % Volume of each concrete plate in m³
Nx = 100; % Number of spatial points
Nt = 1000; % Number of time steps
delta_T = 1; % Temperature increase in K
% Prompt the user for specific input parameters
L1 = input(‘Enter the thickness of the first concrete layer (m): ‘);
L2 = input(‘Enter the thickness of the air layer (m): ‘);
L3 = input(‘Enter the thickness of the second concrete layer (m): ‘);
heat_power = input(‘Enter the heat power (W): ‘);
% Call the function
time_to_increase_temperature = calculate_time_to_increase_temperature( …
rho_concrete, rho_air, k_concrete, k_air, [], cp_concrete, …
cp_air, T_initial, T_surface, L1, L2, L3, volume_P1_P3, [], …
Nx, Nt, delta_T, heat_power);
% Display the result
fprintf(‘Time to increase temperature by 1 K at the right side of P3: %.2f secondsn’, time_to_increase_temperature);
% Plot the result
total_thickness = L1 + L2 + L3;
x = linspace(0, total_thickness, Nx); % Spatial points
y = linspace(0, time_to_increase_temperature, Nx); % Temporal points for plotting
plot(x, y, ‘DisplayName’, ‘Time to Increase Temperature by 1 K’);
xlabel(‘Position (m)’);
ylabel(‘Time (s)’);
legend(‘show’);
title(‘Time to Increase Temperature by 1 K at the right side of P3’);
end solving issue, unknown error, break linkage MATLAB Answers — New Questions