123MM0680 Sparsh Parashar Exp5
123MM0680 Sparsh Parashar Exp5
123MM0680
Sparsh Parashar
Source Code
clc;
clear all;
D0 = 0.000023;
Qd = 14800;
R = 8.314;
T = 900;
D = D0 * exp(-Qd / (R * T));
N = L/dx + 1;
M = Tmax/dt + 1;
Time = 0:dt:Tmax;
XX = 0:dx:L;
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
if isempty(t_index)
error('Time index for t = 600 seconds not found.');
end
% 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);