MATLAB: Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.770081e-17. > In NewtonRaphsomneda (line 415) Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.287521e-18. > In New

now the matlab give me this message for this code
%%General Program For
clc
tic
clear all
% no type Vol del Pg QG Pl Ql Qmax Qmin
busdata= [1 1 1 0 0 0 0 0 0 0; 2 3 1 0 0 0 0 0 0 0; 3 3 1 0 0 0 0 0 0 0; 4 3 1 0 0 0 0.309 0.191 0 0; 5 3 1 0 0 0 0.488 0.303 0 0; 6 3 1 0 0 0 0 0 0 0; 7 3 1 0 0 0 0.309 0.191 0 0; 8 3 1 0 0 0 0 0 0 0; 9 3 1 0 0 0 0.488 0.303 0 0; 10 3 1 0 0 0 0 0 0 0; 11 3 1 0 0 0 0.488 0.303 0 0; 12 3 1 0 0 0 0 0 0 0; 13 3 1 0 0 0 0 0 0 0; 14 3 1 0 0 0 0.488 0.303 0 0; 15 3 1 0 0 0 0.488 0.303 0 0; 16 3 1 0 0 0 0.488 0.303 0 0; 17 3 1 0 0 0 0 0 0 0; 18 3 1 0 0 0 0.488 0.303 0 0; 19 3 1 0 0 0 0 0 0 0; 20 3 1 0 0 0 0.488 0.303 0 0; 21 3 1 0 0 0 0 0 0 0; 22 3 1 0 0 0 0 0 0 0; 23 3 1 0 0 0 0.488 0.303 0 0; 24 3 1 0 0 0 0.488 0.303 0 0; 25 3 1 0 0 0 0.309 0.191 0 0; 26 3 1 0 0 0 0 0 0 0; 27 3 1 0 0 0 0 0 0 0; 28 3 1 0 0 0 0.309 0.191 0 0; 29 3 1 0 0 0 0 0 0 0; 30 3 1 0 0 0 0 0 0 0; 31 3 1 0 0 0 0.193 0.119 0 0; 32 3 1 0 0 0 0 0 0 0; 33 3 1 0 0 0 0 0 0 0; 34 3 1 0 0 0 0.488 0.303 0 0; 35 3 1 0 0 0 0 0 0 0; 36 3 1 0 0 0 0.488 0.303 0 0; 37 3 1 0 0 0 0 0 0 0; 38 3 1 0 0 0 0 0 0 0; 39 3 1 0 0 0 0 0 0 0; 40 3 1 0 0 0 0.488 0.303 0 0; 41 3 1 0 0 0 0.488 0.303 0 0; 42 3 1 0 0 0 0 0 0 0; 43 3 1 0 0 0 0 0 0 0; 44 3 1 0 0 0 0.193 0.119 0 0; 45 3 1 0 0 0 0 0 0 0; 46 3 1 0 0 0 0 0 0 0; 47 3 1 0 0 0 0.309 0.191 0 0; 48 3 1 0 0 0 0 0 0 0; 49 3 1 0 0 0 0 0 0 0; 50 3 1 0 0 0 0.193 0.119 0 0; 51 3 1 0 0 0 0.193 0.119 0 0; 52 3 1 0 0 0 0 0 0 0; 53 3 1 0 0 0 0.193 0.119 0 0; 54 3 1 0 0 0 0 0 0 0; 55 3 1 0 0 0 0.488 0.303 0 0; 56 3 1 0 0 0 0 0 0 0; 57 3 1 0 0 0 0.488 0.303 0 0; 58 3 1 0 0 0 0.193 0.119 0 0; 59 3 1 0 0 0 0 0 0 0; 60 3 1 0 0 0 0 0 0 0; 61 3 1 0 0 0 0.193 0.119 0 0; 62 3 1 0 0 0 0 0 0 0; 63 3 1 0 0 0 0 0 0 0; 64 3 1 0 0 0 0.193 0.119 0 0; 65 3 1 0 0 0 0 0 0 0; 66 3 1 0 0 0 0 0 0 0; 67 3 1 0 0 0 0.488 0.303 0 0; 68 3 1 0 0 0 0.193 0.119 0 0; 69 3 1 0 0 0 0 0 0 0; 70 3 1 0 0 0 0 0 0 0; 71 3 1 0 0 0 0 0 0 0; 72 3 1 0 0 0 0.193 0.119 0 0; 73 3 1 0 0 0 0 0 0 0; 74 3 1 0 0 0 0.193 0.119 0 0; 75 3 1 0 0 0 0 0 0 0; 76 3 1 0 0 0 0.309 0.191 0 0; 77 3 1 0 0 0 0.193 0.119 0 0; 78 3 1 0 0 0 0.193 0.119 0 0; 79 3 1 0 0 0 0 0 0 0; 80 3 1 0 0 0 0 0 0 0; 81 3 1 0 0 0 0.488 0.303 0 0; 82 3 1 0 0 0 0 0 0 0; 83 3 1 0 0 0 0 0 0 0; 84 3 1 0 0 0 0 0 0 0; 85 3 1 0 0 0 0.193 0.119 0 0; 86 3 1 0 0 0 0 0 0 0; 87 3 1 0 0 0 0.193 0.119 0 0; 88 3 1 0 0 0 0 0 0 0; 89 3 1 0 0 0 0.488 0.303 0 0; 90 3 1 0 0 0 0 0 0 0; 91 3 1 0 0 0 0.193 0.119 0 0; 92 3 1 0 0 0 0 0 0 0; 93 3 1 0 0 0 0.488 0.303 0 0; 94 3 1 0 0 0 0 0 0 0; 95 3 1 0 0 0 0.488 0.303 0 0; 96 3 1 0 0 0 0 0 0 0; 97 3 1 0 0 0 0 0 0 0; 98 3 1 0 0 0 0.488 0.303 0 0; 99 3 1 0 0 0 0.488 0.303 0 0; 100 3 1 0 0 0 0.309 0.191 0 0; 101 3 1 0 0 0 0 0 0 0; 102 3 1 0 0 0 0.309 0.191 0 0; 103 3 1 0 0 0 0 0 0 0; 104 3 1 0 0 0 0 0 0 0; 105 3 1 0 0 0 0 0 0 0; 106 3 1 0 0 0 0.488 0.303 0 0; 107 3 1 0 0 0 0 0 0 0; 108 3 1 0 0 0 0.488 0.303 0 0; 109 3 1 0 0 0 0 0 0 0; 110 3 1 0 0 0 0 0 0 0; 111 3 1 0 0 0 0.309 0.191 0 0; 112 3 1 0 0 0 0.193 0.119 0 0; 113 3 1 0 0 0 0.488 0.303 0 0; 114 3 1 0 0 0 0 0 0 0; 115 3 1 0 0 0 0.488 0.303 0 0; 116 3 1 0 0 0 0 0 0 0; 117 3 1 0 0 0 0.309 0.191 0 0; 118 3 1 0 0 0 0 0 0 0; 119 3 1 0 0 0 0 0 0 0; 120 3 1 0 0 0 0 0 0 0; 121 3 1 0 0 0 0.193 0.119 0 0; 122 3 1 0 0 0 0 0 0 0; 123 3 1 0 0 0 0.193 0.119 0 0; 124 3 1 0 0 0 0 0 0 0; 125 3 1 0 0 0 0.193 0.119 0 0; 126 3 1 0 0 0 0 0 0 0; 127 3 1 0 0 0 0 0 0 0; 128 3 1 0 0 0 0.488 0.303 0 0; 129 3 1 0 0 0 0 0 0 0; 130 3 1 0 0 0 0 0 0 0; 131 3 1 0 0 0 0.488 0.303 0 0; 132 3 1 0 0 0 0 0 0 0; 133 3 1 0 0 0 0.488 0.303 0 0; 134 3 1 0 0 0 0 0 0 0; 135 3 1 0 0 0 0.309 0.191 0 0; 136 3 1 0 0 0 0 0 0 0; 137 3 1 0 0 0 0.309 0.191 0 0; 138 3 1 0 0 0 0 0 0 0; 139 3 1 0 0 0 0.488 0.303 0 0; 140 3 1 0 0 0 0 0 0 0; 141 3 1 0 0 0 0.193 0.119 0 0; 142 3 1 0 0 0 0.193 0.119 0 0];
% From To R X B Tap % Bus Bus (pu) (pu) (pu) Ratio
linedata=[ 54 55 0.3131409 1.878846 0 1; 49 51 3.162278 9.486834 0 1; 71 72 3.162278 9.486834 0 1; 17 18 0.3131409 1.878846 0 1; 94 95 0.3131409 1.878846 0 1; 92 93 0.3131409 1.878846 0 1; 4 25 1.030651 3.86494 0 1; 103 123 3.162278 9.486834 0 1; 30 31 3.162278 9.486834 0 1; 104 111 1.030651 3.86494 0 1; 109 112 3.162278 9.486834 0 1; 134 135 1.030651 3.86494 0 1; 42 128 0.3131409 1.878846 0 1; 43 44 3.162278 9.486834 0 1; 73 74 3.162278 9.486834 0 1; 88 142 3.162278 9.486834 0 1; 101 102 1.030651 3.86494 0 1; 114 113 0.3131409 1.878846 0 1; 130 131 0.3131409 1.878846 0 1; 86 87 3.162278 9.486834 0 1; 124 125 3.162278 9.486834 0 1; 63 64 3.162278 9.486834 0 1; 90 91 3.162278 9.486834 0 1; 48 50 3.162278 9.486834 0 1; 10 11 0.3131409 1.878846 0 1; 12 14 0.3131409 1.878846 0 1; 107 108 0.3131409 1.878846 0 1; 38 41 0.3131409 1.878846 0 1; 116 115 0.3131409 1.878846 0 1; 46 47 1.030651 3.86494 0 1; 27 28 1.030651 3.86494 0 1; 126 106 0.3131409 1.878846 0 1; 22 24 0.3131409 1.878846 0 1; 79 78 3.162278 9.486834 0 1; 75 76 1.030651 3.86494 0 1; 52 53 3.162278 9.486834 0 1; 59 58 3.162278 9.486834 0 1; 60 61 3.162278 9.486834 0 1; 65 68 3.162278 9.486834 0 1; 35 36 0.3131409 1.878846 0 1; 136 137 1.030651 3.86494 0 1; 138 139 0.3131409 1.878846 0 1; 56 57 1.030651 3.86494 0 1; 3 5 0.3131409 1.878846 0 1; 8 9 0.3131409 1.878846 0 1; 66 67 0.3131409 1.878846 0 1; 33 98 0.3131409 1.878846 0 1; 33 99 0.3131409 1.878846 0 1; 33 100 1.030651 3.86494 0 1; 83 89 0.3131409 1.878846 0 1; 70 77 3.162278 9.486834 0 1; 39 40 0.3131409 1.878846 0 1; 122 121 3.162278 9.486834 0 1; 119 117 1.030651 3.86494 0 1; 140 141 3.162278 9.486834 0 1; 21 23 0.3131409 1.878846 0 1; 80 81 0.3131409 1.878846 0 1; 19 20 0.3131409 1.878846 0 1; 84 85 3.162278 9.486834 0 1; 13 15 0.3131409 1.878846 0 1; 13 16 0.3131409 1.878846 0 1; 6 7 1.030651 3.86494 0 1; 32 34 0.3131409 1.878846 0 1; 132 133 0.3131409 1.878846 0 1; 1 2 7.067975 4.334504 0 1; 3 2 1.738946 1.066426 0 1; 3 6 1.121901 0.6880165 0 1; 6 8 1.738946 1.066426 0 1; 8 10 1.738946 1.066426 0 1; 6 12 1.738946 1.066426 0 1; 12 13 1.738946 1.066426 0 1; 2 4 3.365702 2.064049 0 1; 4 26 4.824173 2.958471 0 1; 26 29 4.487603 2.752066 0 1; 29 35 7.292354 4.472107 0 1; 35 32 7.853304 4.816115 0 1; 32 37 6.731404 4.128099 0 1; 37 39 2.019421 1.23843 0 1; 37 38 6.394834 3.921694 0 1; 38 42 1.738946 1.066426 0 1; 29 30 8.526444 5.228925 0 1; 26 27 5.048553 3.096074 0 1; 4 17 7.292354 4.472107 0 1; 17 21 4.038843 2.47686 0 1; 17 19 0.8975205 0.5504132 0 1; 21 22 4.151032 2.545661 0 1; 22 43 6.170454 3.784091 0 1; 43 45 6.170454 3.784091 0 1; 45 62 0.5048553 0.3096074 0 1; 45 48 0.4487603 0.2752066 0 1; 45 46 1.738946 1.066426 0 1; 65 62 3.814462 2.339256 0 1; 62 63 9.199586 5.641736 0 1; 65 66 5.609503 3.440082 0 1; 65 69 4.824173 2.958471 0 1; 48 49 5.609503 3.440082 0 1; 49 52 8.975205 5.504132 0 1; 52 54 10.09711 6.192148 0 1; 54 60 13.46281 8.256198 0 1; 54 56 13.46281 8.256198 0 1; 60 59 10.09711 6.192148 0 1; 69 71 4.487603 2.752066 0 1; 69 70 6.170454 3.784091 0 1; 71 80 7.516735 4.609711 0 1; 88 73 1.795041 1.100826 0 1; 79 75 5.609503 3.440082 0 1; 82 80 11.21901 6.880165 0 1; 80 92 5.160743 3.164876 0 1; 92 94 4.936363 3.027273 0 1; 94 96 5.272933 3.233678 0 1; 96 97 6.731404 4.128099 0 1; 84 86 2.243801 1.376033 0 1; 82 83 1.121901 0.6880165 0 1; 83 84 7.292354 4.472107 0 1; 90 83 4.319318 2.648864 0 1; 124 90 9.984916 6.123347 0 1; 96 110 1.907231 1.169628 0 1; 97 101 5.609503 3.440082 0 1; 101 103 7.292354 4.472107 0 1; 105 126 4.487603 2.752066 0 1; 110 105 8.414255 5.160124 0 1; 104 105 4.038843 2.47686 0 1; 109 104 2.243801 1.376033 0 1; 105 107 4.151032 2.545661 0 1; 114 109 5.272933 3.233678 0 1; 116 114 3.814462 2.339256 0 1; 118 116 1.458471 0.8944215 0 1; 127 118 2.468182 1.513636 0 1; 127 120 1.682851 1.032025 0 1; 120 122 1.907231 1.169628 0 1; 118 119 1.795041 1.100826 0 1; 42 129 8.975205 5.504132 0 1; 129 130 3.029132 1.857645 0 1; 132 129 1.738946 1.066426 0 1; 134 132 6.170454 3.784091 0 1; 136 134 7.292354 4.472107 0 1; 138 136 10.09711 6.192148 0 1; 127 140 2.243801 1.376033 0 1; 75 88 9.536156 5.84814 0 1; 97 33 3.365702 2.06404 0 1; 73 69 0.01121901 0.006880165 0 1];
fb=linedata(:,1);
tb=linedata(:,2);
r=linedata(:,3);
x=linedata(:,4);
b=linedata(:,5);
a=linedata(:,6);
z=r+1i*x;
y=1./z;
b=1i*b;
nl=length(fb);
nbus=max(max(fb),max(tb));
Y=zeros(nbus,nbus);
for k=1:nl
Y(fb(k),tb(k))=Y(fb(k),tb(k))-y(k)/a(k);
Y(tb(k),fb(k))=Y(fb(k),tb(k));
end
for m=1:nbus
for n=1:nl
if fb(n)==m
Y(m,m)=Y(m,m)+y(n)/a(n)^2+b(n);
elseif tb(n)==m
Y(m,m)=Y(m,m)+y(n)+b(n);
end
end
end
G=real(Y);
B=imag(Y);
BMva=100;
busNo=busdata(:,1);
type=busdata(:,2);
V=busdata(:,3);
del=busdata(:,4);
Pg=busdata(:,5)/BMva;
Qg=busdata(:,6)/BMva;
Pl=busdata(:,7)/BMva;
Ql=busdata(:,8)/BMva;
Qmin=busdata(:,9)/BMva;
Qmax=busdata(:,10)/BMva;
pv=find(type==2|type==1);
pq=find(type==3);
npq=length(pq);
npv=length(pv);
Psp=Pg-Pl;
Qsp=Qg-Ql;
Iter=1;
Tol=1;
while Tol>1e-5
P=zeros(nbus,1);
Q=zeros(nbus,1);
for i=1:nbus
for j=1:nbus
P(i)=P(i)+V(i)*V(j)*(G(i,j)*cos(del(i)-del(j))+B(i,j)*sin(del(i)-del(j)));
Q(i)=Q(i)+V(i)*V(j)*(G(i,j)*sin(del(i)-del(j))-B(i,j)*cos(del(i)-del(j)));
end
end
if Iter>2 && Iter<=7
for n=2:nbus
if type(n)==2;
QG=Q(n)+Ql(n);
if QG > Qmax(n)
V(n)=V(n)-0.01;
elseif QG < Qmin(n)
V(n)=V(n)+0.01;
end
end
end
end
dPa=Psp-P;
dQa=Qsp-Q;
dP=dPa(2:nbus);
k=1;
dQ=zeros(npq,1); for i=1:nbus if type(i)==3 dQ(k,1)=dQa(i); k=k+1; end end M=[dP;dQ]; J1=zeros(nbus-1,nbus-1); for i=1:nbus-1 m=i+1; for j=1:nbus-1; n=j+1; if m==n for n=1:nbus J1(i,j)=J1(i,j)+V(m)*V(n)*(-G(m,n)*sin(del(m)-del(n))+B(m,n)*cos(del(m)-del(n))); end J1(i,j)=J1(i,j)-V(m)^2*B(m,m); else J1(i,j)=V(m)*V(n)*(G(m,n)*sin(del(m)-del(n))-B(m,n)*cos(del(m)-del(n))); end end end J2=zeros(nbus-1,npq); for i=1:nbus-1 m=i+1; for j=1:npq n=pq(j); if m==n for n=1:nbus J2(i,j)=J2(i,j)+V(n)*(G(m,n)*cos(del(m)-del(n))+B(m,n)*sin(del(m)-del(n))); end J2(i,j)=J2(i,j)+V(m)*G(m,m); else J2(i,j)=V(m)*(G(m,n)*cos(del(m)-del(n))+B(m,n)*sin(del(m)-del(n))); end end end J3=zeros(npq,nbus-1); for i=1:npq m=pq(i); for j=1:nbus-1 n=j+1; if m==n for n=1:nbus J3(i,j)=J3(i,j)+V(m)*V(n)*(G(m,n)*cos(del(m)-del(n))+B(m,n)*sin(del(m)-del(n))); end J3(i,j)=J3(i,j)-V(m)^2*G(m,m); else J3(i,j)=V(m)*V(n)*(-G(m,n)*cos(del(m)-del(n))-B(m,n)*sin(del(m)-del(n))); end end end J4=zeros(npq,npq); for i=1:npq m=pq(i); for j=1:npq n=pq(j); if m==n for n=1:nbus J4(i,j)=J4(i,j)+V(n)*(G(m,n)*sin(del(m)-del(n))-B(m,n)*cos(del(m)-del(n))); end J4(i,j)=J4(i,j)-V(m)*B(m,m); else J4(i,j)=V(m)*(G(m,n)*sin(del(m)-del(n))-B(m,n)*cos(del(m)-del(n))); end end end J=[J1 J2;J3 J4]; X=inv(J)*M; dTh=X(1:nbus-1); dV=X(nbus:end); del(2:nbus)=del(2:nbus)+dTh; k=1; for n=2:nbus if type(n)==3 V(n)=V(n)+dV(k); k=k+1; end end Iter=Iter+1; Tol=max(abs(M)); end Q=zeros(nbus,1); for i=1:nbus for j=1:nbus P(i)=P(i)+V(i)*V(j)*(G(i,j)*cos(del(i)-del(j))+B(i,j)*sin(del(i)-del(j))); Q(i)=Q(i)+V(i)*V(j)*(G(i,j)*sin(del(i)-del(j))-B(i,j)*cos(del(i)-del(j))); end end for i=1:nbus del(i)=180*del(i)/pi; end disp('----------------------------------------'); disp(' Newton Raphson Loadflow Solution '); disp('----------------------------------------'); disp(' Bus | |Voltage Angle |'); disp(' | No. pu | |Radian'); disp('----------------------------------------'); for m=1:nbus fprintf(' %3g ' ,m); fprintf(' %8.3f ' ,V(m)); fprintf(' %8.3f ' ,del(m)); fprintf(' %8.3f ',Pg(m)*BMva); if type(m)==2 fprintf(' %8.3f ',(Q(m)+Ql(m))*BMva);
end
fprintf('\n');
end
disp('----------------------------------------');
fprintf( 'Number Of Ieration %3g \n',Iter)
toc

Best Answer

The message is clear: You solve an matzrix equation with a matrix which is badly conditioned. This might be caused by a programming error (this would be sad, because it looks impossible to debug your code - it is simply not readable due to the absence of comments) or the problem is instable itself.