Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.4K Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

While loop for power iteration of a diffusion problem

Posted 4 years ago
POSTED BY: Robert Atwell
3 Replies

Your code initializes with k and fluxdiff being numbers but after one iteration k and fluxdiff are lists. Your while condition specifies fluxdiff >0.0001. But {number} > 0.001 will stop the iterations. For the second iteration, your code crashes because k is also becoming a list.

This should do the trick

out = First@Last@Reap@While[fluxdiff > 0.0001,
      oldflux = flux;
      oldk = k;
      oldsource = source;
      iteration += 1;

      flux = 1/oldk LinearSolve[a, oldsource];
      source = b flux;
      k = First[oldk Total[source]/Total[oldsource]];
      fluxdiff = 0;
      fluxdiff = First[RootMeanSquare[flux - oldflux]];
      Sow[{iteration, flux, source, k, fluxdiff}];
      ];
Grid@out
POSTED BY: Martijn Froeling

Is the IWhile intentional, or a typo?

POSTED BY: Daniel Lichtblau
Posted 4 years ago

It's a typo, the issue exists without the typo.

POSTED BY: Robert Atwell
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard