0% found this document useful (0 votes)
17 views

123MM0680 Sparsh Parashar Exp5

Uploaded by

sanidhya01jindal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

123MM0680 Sparsh Parashar Exp5

Uploaded by

sanidhya01jindal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment -5

123MM0680
Sparsh Parashar

Source Code
clc;
clear all;

D0 = 0.000023;
Qd = 14800;
R = 8.314;
T = 900;

D = D0 * exp(-Qd / (R * T));

L = 0.5; % Length of the material in meters


Tmax = 600; % Simulation time in seconds
dx = 0.001; % Spatial step (meters)
dt = 0.1; % Time step (seconds)
LB = 500; % Left boundary temperature (K)
RB = 298; % Right boundary temperature (K)
IC = 298; % Initial condition (K)

N = L/dx + 1;
M = Tmax/dt + 1;
Time = 0:dt:Tmax;
XX = 0:dx:L;

lambda = (D * dt / (dx * dx)) / 2;


U = zeros(M, N);

for t = 1:M
U(t,1) = LB;
U(t,N) = RB;
end
for i = 2:N-1
U(1,i) = IC;
end

A = zeros(N-2, N-2);
A(1,1) = 1 + 2 * lambda;
A(1,2) = -lambda;
A(N-2,N-2) = 1 + 2 * lambda;
A(N-2,N-3) = -2*lambda;
for i = 2:N-3
A(i,i) = 1 + 2 * lambda;
A(i,i-1) = -lambda;
A(i,i+1) = -lambda;
end

for t = 2:M
B = zeros(N-2,1);
B(1) = lambda * U(t-1,1) + (1 - 2 * lambda) * U(t-1,2) + lambda * U(t-1,3) + lambda * U(t,1);
B(N-2) = lambda * U(t-1,N-2) + (1 - 2 * lambda) * U(t-1,N-1) + lambda * U(t-1,N) + lambda *
U(t,N);

for i = 2:N-3
B(i) = lambda * U(t-1,i+2) + (1 - 2 * lambda) * U(t-1,i+1) + lambda * U(t-1,i);
end

Z = A \ B;
U(t,2:N-1) = Z';
end

% Find the case depth at 600 seconds


t_600 = 600; % Time in seconds
t_index = find(Time >= t_600, 1);

if isempty(t_index)
error('Time index for t = 600 seconds not found.');
end

temp_at_600 = U(t_index, :); % Temperature profile at t = 600 seconds

% Set threshold temperature as 90% of surface temperature


threshold_temp = LB * 0.9;

% Find the position (depth) where the temperature drops below the threshold
case_depth_index = find(temp_at_300 <= threshold_temp, 1);

if isempty(case_depth_index)
error('Threshold temperature not reached within the material.');
end

case_depth = XX(case_depth_index);

fprintf('Case depth at t = 600 seconds: %f meters\n', case_depth);

% Plot Temperature vs Distance at t = 600 seconds


figure(1);
plot(XX, temp_at_600, '-o');
xlabel('Distance (m)');
ylabel('Temperature (K)');
title('Temperature vs Distance at t = 600 seconds');
grid on;

% Plot Temperature vs Time at node 100


node_100 = 100;
figure(2);
plot(Time, U(:, node_100), '-o');
xlabel('Time (s)');
ylabel('Temperature (K)');
title('Temperature vs Time at Node 100');
grid on;
Output

You might also like