I am trying to use a While loop to solve for a diffusion problem using the power iteration method. The code is supposed to loop through three equations (flux, source, and k) until the fluxdiff > 0.0001. I am trying get this code to plot the flux and print a table of the flux, k, source, and fluxdiff. Right now the code does not produce any outputs and I am not sure where the problem(s) is/are. If there's a way to use a "Table" to solve this problem, I am willing to try it.
sigmaa = .1532;
\[Nu]sigmaf = .1570;
d = 1/(3 (.0362));
nodes3 = 4;
r1 = 1;
dr1 = r1/nodes3
a =
Table[If[i == j, sigmaa*i*dr1*dr1 + (2 i dr1 d)/dr1,
If[i - j == 1, -d/dr1 (i*dr1 - dr1/2),
If[i - j == -1, -d/dr1 (i*dr1 + dr1/2), 0]]], {i, 0, 3}, {j, 0,
3}];
anew = ReplacePart[a, {1, 1} -> d/2 + sigmaa dr1^2/8]
b = Table[If[i == 1, \[Nu]sigmaf/2, \[Nu]sigmaf], {i, 1, nodes3}, {j, 1}]
flux = {{1}, {1}, {1}, {1}};
k = 1.0000;
source = b flux
fluxdiff = 1;
iteration = 0;
oldflux = flux;
oldk = k;
oldsource = source;
While[fluxdiff > 0.0001,
Print[iteration, flux, source, k, fluxdiff];
oldflux = flux;
oldk = k;
oldsource = source;
iteration = iteration + 1;
flux = 1/oldk LinearSolve[a, oldsource];
source = b flux;
k = oldk Total[source]/Total[oldsource];
fluxdiff = 0;
fluxdiff = RootMeanSquare[flux - oldflux];
]