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 .

조회 수: 7 (최근 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
Sreedhar Arumugam 2021년 9월 7일

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by