Uploaded by dushyantdchss

1d heat

advertisement
% 1d heat conduction equation solution by crank nicolesn method
clear all
clc
%% Define the problem
dt = 0.001;
dx = 0.005;
X = 0:0.005:1;
alpha = 2*10e-6;
r = (alpha*dt)/(2*dx*dx);
%% Initialize the problem
t1 = 0;
tr = 100;
u(1:199) = 25; % here u indicate temperature
m = 199;
T(m,m) = 0;
T(1:m+1:m*m) = 1+2*r;
T(2:m+1:m*m) = -r;
T(m+1:m+1:m*m) = -r;
%% calculation
for j = 1:200000
d(1) = 2*r*t1 + (1-2*r)*u(1) + r*u(2);
d(199) = 2*r*tr + (1-2*r)*u(199) + r*u(198);
for i = 2:198
d(i) = r*u(i-1)+(1-2*r)*u(i)+r*u(i+1);
end
w = d.';
Z = inv(T)*w;
u=Z;
end
%% plotting
Y = [t1, Z.', tr];
plot(X,Y,'-r');
Result
Distance vs temperature plot
Related documents
Download