central difference coefficient matrix

조회 수: 4 (최근 30일)
Faraz Vossoughian
Faraz Vossoughian 2020년 5월 4일
Hi im trying to code the following coefiicient matrix A in a for loop in Matlab. N is the total number of elements. And i and j are obtained from k. could someone help me please code the A matrix correctly for any N value.
for k=1:N
A(k,k) = 4; % the diagonal element, corresponding to Tij, is always 4
% In the following, we look at the four neighbours of (i,j) that are
% involved in the 5-point formula
i = mod(k-1,nx)+1; j = (k-i)/nx+1; %get (i,j) from k
%boundary condtion
if i==1
b(k,1)=Tl;
elseif i==nx
b(k,1)=Tr;
elseif j==1
b(k,1)=Tb;
elseif j==ny
b(k,1)=Tt;
end
%A matrix construction
if i>1 && j>1
if i==j
A(j-1,i)=-1;
A(j,i+1)=-1;
A(j,i-1)=-1;
A(j+1,i)=-1;
end
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by