code is returning NaN when taking inverse of matrx

조회 수: 28 (최근 30일)
Alyssa Heisey
Alyssa Heisey 2019년 11월 19일
댓글: Vladimir Sovkov 2019년 11월 19일
clear all;close all;clc
N = 11; %number of nodes per row
Ntot = N^2; %total number of nodes
L = 25; %cm
W = 25; %cm
dx = L/(N-1); %cm
As=25*25;
x = 0:dx:L; %cm
tinf = 298; %C
h = 20; %W/m2K
k = 16.2; %W/mK
tin = 1500; %K
A = zeros(Ntot,Ntot);
b = zeros(Ntot,1);
A(1,1) = 2*h*dx + 2*k; % top left node
A(1,2) = -k;
A(1,N+1) = -k;
b(1,1) = 2*h*dx*tinf;
A(N,N) = 2*h*dx + 2*k; %top right node
A(N,N-1) = -k;
A(N,N+N) = -k;
b(N,1) = 2*h*dx*tinf;
for i= Ntot-(N-1)
A(i,i) = 2*h*dx+2*k ; %bottom left node
A(i,i+1) = -k;
A(i,i-N) = -k;
b(i,1) = tinf*2*h*dx;
end
for i= Ntot
A(i,i) = 2*h*dx+2*k ; %bottom right node
A(i,i-1) = -k;
A(i,i-N) = -k;
b(i,1) = tinf*2*h*dx;
end
for i= 2:10
A(i,i) = 2*k +h*dx ;
A(i,i-1) = -k;
A(i,i+1) = -k;
b(i,1)= dx*(As*tin+tinf*h);
end
for i= 112:120
A(i,i) = 2*k +h*dx ;
A(i,i-1) = -k;
A(i,i+1) = -k;
b(i,1)= dx*(h*tin+tinf*h);
end
for i=12:11:100
A(i,i) = h*dx+2*k;
A(i,i-11)=-k;
A(i,i+11) = -k;
b(i,1) = dx*(h*tinf + tin*As);
end
for i=22:11:110
A(i,i) = h*dx+2*k;
A(i,i-11)=-k;
A(i,i+11) = -k;
b(i,1) = dx*(h*tinf + tin*As);
end
for i=13:21
b(i,1)=tin;
end
for i=24:32
b(i,1)=tin;
end
for i=35:43
b(i,1)=tin;
end
for i=46:54
b(i,1)=tin;
end
for i=57:65
b(i,1)=tin;
end
for i=68:76
b(i,1)=tin;
end
for i=79:87
b(i,1)=tin;
end
for i=90:98
b(i,1)=tin;
end
for i=101:109
b(i,1)=tin;
end
T = A\b
Tf = transpose(reshape(T,11,11));
contourf(Tf)
  댓글 수: 4
Walter Roberson
Walter Roberson 2019년 11월 19일
편집: Walter Roberson 2019년 11월 19일
rank(A) is 40, on a 121 x 121 matrix, so the condition number will not be of importance in this particular case.
Have a look at spy(A) and it will become obvious that there are number of all-zero columns and all-zero rows. For example observe that nothing in your code sets anything in row 13 of A.
Vladimir Sovkov
Vladimir Sovkov 2019년 11월 19일
Search and read Matlab "Help" for the "pinv" call function and, if it suits you, change "T = A\b" to "T = pinv(A)*b".

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by