I have to solve 1d heat equation using ftcs with given boundry condition. u(0,t)=0, u(l,t)=0 u(x,0) = f(x) but i cannot understand how to use my this in for loop .

22 views (last 30 days)
f(x)=100; %given value of function
h = 0.1;% given value of step size
k = 0.01;%given value of time-step size
alpha = 0.25; % given value of thermal diffusivity in heat equation
lambda = alpha*k/h^2; %Difference method parameter
l = 1 ; % legth of thin rod
t = 1 ; % final time
n = l/h ; % intervals at x-axis
% W - Matrix for generating solutions
W(0,t)=W(l,t) = 0 ; %Dirichlet boundry conditions
% imposition of boundry conditions
W =zeroes (length(x), length(t));
W(:,1)=f(x); %intial condition
W(1,:)=0.0; %condition at x = 0
W(end,:)=0.0; %condition at x = L
%genrating the matrix
x = (0:h:l);
t=(0:k:t)';
W = zeroes(length(x), Length(t));
for i = 0:0.1
for j = 0:0.001
W(i,j) = W((1-2*lambda)*ones(n-1,1),0) + (lambda*ones(n-2,1),1) ;
end
end

Answers (1)

Sreedhar Arumugam
Sreedhar Arumugam on 7 Sep 2021

Categories

Find more on Heat and Mass Transfer in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!