why does it give this result???

4 views (last 30 days)
Rebecca D'Onofrio
Rebecca D'Onofrio on 11 Sep 2021
Answered: Tanmay Das on 13 Sep 2021
the code works well up to the moment I introduce the while loop. It says: "Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate.
RCOND = NaN.
> In progettofinale (line 84)"
then, it always gives as a result BFinale=0 and consequently RAGGIO=inf
why??
nmax=100;
COEFFICIENTI=zeros(26,26);
BUCKLING=zeros(1,nmax);
K=zeros(1,nmax);
FLUSSI=zeros(26,nmax);
FLUSSIN=zeros(26,nmax);
B1=6E-5;
FLUSSO0=zeros(26,1);
for ii=1:26
FLUSSO0(ii)=1/F(ii);
end
for ii=1:26
for jj=1:26
for ii=jj
COEFFICIENTI(ii,jj)=D(ii).*B1+REMOVAL(ii);
end
end
end
for ii=2:26
COEFFICIENTI(ii,(ii-1))=-ELREM(ii);
end
for ii=1:26
for jj=1:26
COEFFICIENTI(ii,jj)=COEFFICIENTI(ii,jj)-INELASTIC(ii,jj);
end
end
FLUSSI(:,1)=COEFFICIENTI\X;
K1=F'.*FLUSSI(:,1);
FLUSSIN(:,1)=FLUSSI(:,1)\K1;
if K1>1
B2=B1+(0.5*B1);
else if K1<1
B2=B1-(0.5*B1);
end
end
for ii=1:26
for jj=1:26
for ii=jj
COEFFICIENTI(ii,jj)=D(ii).*B2+REMOVAL(ii);
end
end
end
FLUSSI(:,2)=COEFFICIENTI\X;
K2=F'.*FLUSSI(:,2);
FLUSSIN(:,2)=FLUSSI(:,2)\K2;
%dalla 3 iterazione in poi si può utilizzare l'interpolazione lineare, servendosi dei
%due precedenti valori di B per calcolare quello successivo:
n=3;
while abs(K2-1)>10^-5 & n<nmax
BUCKLING(n)=BUCKLING(n-1)+(BUCKLING(n-2)-BUCKLING(n-1))*(1-K(n-1))\(K(n-2)-K(n-1));
for ff=1:26
for ll=1:26
for ff=ll
COEFFICIENTI(ff,ll)=D(ff).*BUCKLING(n)+REMOVAL(ff);
end
end
end
FLUSSI(:,n)=COEFFICIENTI\X;
Kn=F'.*FLUSSI(:,n);
FLUSSIN(:,n)=FLUSSI(:,n)\Kn;
errorenuovo=abs(Kn-1);
iterazioni=n;
n=iterazioni+1;
end
BFinale=BUCKLING(n)
RAGGIO=pi/(sqrt(BFinale))

Answers (1)

Tanmay Das
Tanmay Das on 13 Sep 2021
Hi,
In the while loop part of the code, mldivide(\) operator is used which has the same precedence as that of matrix multiplication(*). So, (BUCKLING(n-2)-BUCKLING(n-1))*(1-K(n-1)) becomes 0. Also the value of (K(n-2)-K(n-1)) is 0. Hence, it is of the form 0 \ 0 which is returning NaN. That is why there is a warning that "Matrix is singular, close to singular or badly scaled. Results may be inaccurate". If you change the line to:
BUCKLING(n)=BUCKLING(n-1)+(BUCKLING(n-2)-BUCKLING(n-1))*((1-K(n-1))\(K(n-2)-K(n-1)));
then this particular warning issue may get resolved. But still you will get BFinale=0 and RAGGIO=inf as the form of (BUCKLING(n-2)-BUCKLING(n-1))*((1-K(n-1))\(K(n-2)-K(n-1))) is still 1 \ 0 which will always return zero and the value of BUCKLING(n) will never increase for any value of n. Hence, it is recommended to check the code as well as the names of variables once again.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!