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 次查看(过去 30 天)
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

回答(1 个)

Sreedhar Arumugam

类别

Help CenterFile Exchange 中查找有关 Heat and Mass Transfer 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by