Index exceeds the number of array elements (100). Error in interpolazione (line 149) BFin=B(n); %buckling finale

1 view (last 30 days)
D=D39+D40+DO+DNa+DFe; %coefficienti di diffusione
F=F39+F40; %prodotti di fissione
CAPTURE=[Pu39capture+Pu40capture+Nacapture+Fecapture+Ocapture]; %sigma di cattura
FISSION=[Pu39fission+Pu40fission]; %sigma di fissione
ELREM=[Pu39elrem+Pu40elrem+Naelrem+Feelrem+Oelrem]; %sigma di scattering elastico(direclty coupled)
%si passa alla creazione delle matrici che serviranno per i sucessivi
%calcoli dei flussi normalizzati e non, di B, di K. inoltre si assegna un valore di partenza a
%B, e si calcola un flusso iniziale
Buckling=zeros(1,nmax);
K=zeros(1,nmax);
FLUSSIN=zeros(26,nmax)
FLUSSI=zeros(26,nmax)
FLUX0=zeros(26,1);
B1=0.00006;
nmax=1000;
for ii=1:26
FLUX0(ii)=1/F(ii);
end
%definisco la matrice dei coefficienti andando prima a riempire la diagonale di una matrice vuota
A=zeros(26,26);
for ii=1:26
for jj=1:26
for ii=jj
A(ii,jj)=D(ii).*B1+REMOVAL(ii);
end
end
end
% e successivamente aggiungendo i termini di scattering
% ottenendo una matrice triangolare inferiore
for jj=1:26
if ii~=jj
M(ii,jj)=A(ii,jj)-ELREM(ii)-INELASTIC(ii,jj);
end
end
for ii=1:26
for jj=1:26
COEFFICIENTI(ii,jj)=M(ii,jj)+A(ii,jj);
end
end
%risolvo il sistema:
FLUSSI=COEFFICIENTI^-1.*MATFIS; %flusso non normalizzato
K1=F.*FLUSSI; %calcolo del K
FLUSSIN=FLUSSI/K1; %calcolo del flusso normalizzato
%devo cambiare B in base a K1:
if K1>1
B2=B1+0.5*B1;
elseif K1<1
B2=B1-0.5*B1;
end
%definisco nuovamente la matrice dei coefficienti
A=zeros(26,26);
for ii=1:26
for jj=1:26
for ii=jj
A(ii,jj)=D(ii).*B2+REMOVAL(ii);
end
end
end
for jj=1:26
if ii~=jj
M(ii,jj)=A(ii,jj)-ELREM(ii)-INELASTIC(ii,jj);
end
end
for ii=1:26
for jj=1:26
COEFFICIENTI(ii,jj)=M(ii,jj)+A(ii,jj);
end
end
%risolvo nuovamente il sistema:
FLUSSI(:,2)=COEFFICIENTI\X; %flusso non normalizzato
K2=F'*FLUSSI(:,1); %calcolo del K
FLUSSIN(:,2)=FLUSSI(:,2)/K2; %calcolo del flusso normalizzato
epsilon=10^-6; %definisco la tolleranza
er=abs((K2-1)); %definisco l'errore
while er>epsilon & n<nmax
n=3;
B(n)=B(n-1)+((B(n-1)-B(n-2))*(1-K(n-1)))/(K(n-1)-K(n-2));
%ridefinisco la matrice dei coefficienti
A=zeros(26,26);
for ii=1:26
for jj=1:26
for ii=jj
A(ii,jj)=D(ii).*B(n)+REMOVAL(ii);
end
end
end
for jj=1:26
if ii~=jj
M(ii,jj)=A(ii,jj)-ELREM(ii)-INELASTIC(ii,jj);
end
end
for ii=1:26
for jj=1:26
COEFFICIENTI(ii,jj)=M(ii,jj)+A(ii,jj);
end
end
%risolvo nuovamente il sistema:
FLUSSI(:,n)=COEFFICIENTI\X; %flusso non normalizzato
Kn=F*FLUSSI(:,n); %calcolo del K
FLUSSIN(:,n)=FLUSSI(:,n)/Kn; %calcolo del flusso normalizzato
%ridefinisco l'errore
err=abs(Kn-1);
iterazioni=n;
n=iterazioni+1;
end
BFin=B(n); %buckling finale
R=pi/sqrt(BFin)

Answers (1)

Tanmay Das
Tanmay Das on 16 Sep 2021
Hi,
The variable B has not been initialized anywhere within the limits of the code that has been attached. So, the following piece of code initializes a 1-D array B with length 3:
while er>epsilon & n<nmax
n=3;
B(n)=B(n-1)+((B(n-1)-B(n-2))*(1-K(n-1)))/(K(n-1)-K(n-2));
And this piece of code increments n to 4:
err=abs(Kn-1);
iterazioni=n;
n=iterazioni+1;
So, the following piece of code tries to access the 4th element of B(of length 3) and hence, is generating Index exceeds the number of array elements error.
BFin=B(n); %buckling finale
Here is a possible workaround. I suppose the line below:
Buckling=zeros(1,nmax);
should be modified to:
B=zeros(1,nmax);
This will initialize a 1-D array of length "nmax". Also, the following lines are not logically correct:
while er>epsilon & n<nmax
n=3;
B(n)=B(n-1)+((B(n-1)-B(n-2))*(1-K(n-1)))/(K(n-1)-K(n-2));
as this will ensure that n sticks to the value 3 and the control never comes out of the loop if n>nmax. I suppose n should be initialized before the while loop begins and the piece of code should be modified to:
n=3;
while er>epsilon & n<nmax
B(n)=B(n-1)+((B(n-1)-B(n-2))*(1-K(n-1)))/(K(n-1)-K(n-2));

Tags

Community Treasure Hunt

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

Start Hunting!