Message Boards Message Boards

0
|
4647 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

[?] Avoid issue with message that "symbol does not have immediate value"?

Posted 4 years ago

Consider the following code:

InitializationValue[isingarray] = 2 RandomInteger[{0, 1}, {100, 100}] - 1

Do [temp = 
   beta*(isingarray[[i + 1, j]] + isingarray[[i, j + 1]] +  isingarray[[i - 1, j]] + isingarray[[i, j - 1]]);
  z = E^temp + E^-temp;
  isingarray[[i, j]] = If[(E^-temp)/z > RandomReal[{0, 1}], 1, -1], {i, 2, 99}, {j, 2, 99}];

Set::noval: Symbol isingarray in part assignment does not have an immediate value.

POSTED BY: Fred Kuttner
4 Replies
Posted 4 years ago

Henrik,

I tried that, and it didn't work until I added:

Initialize[isingarray]

Fred

POSTED BY: Fred Kuttner

It's always the little language-specific features that hang one up learning a new language.

Hello Fred,

just as a remark: Are you aware that you can simply wright:

isingarray = 2 RandomInteger[{0, 1}, {100, 100}] - 1;

Do [
temp = beta*(isingarray[[i + 1, j]] + isingarray[[i, j + 1]] + isingarray[[i - 1, j]] + isingarray[[i, j - 1]]);
z = E^temp + E^-temp; isingarray[[i, j]] = If[(E^-temp)/z > RandomReal[{0, 1}], 1, -1], {i, 2, 99}, 
{j, 2, 99}];

You do not need to use InitializationValue and the like - (nearly) nobody needs those functions, and they are qualified as "Experimental".

Regards -- Henrik

POSTED BY: Henrik Schachner
Posted 4 years ago

That worked! Thanks so much. It's always the little language-specific features that hang one up learning a new language.

POSTED BY: Fred Kuttner
Posted 4 years ago

Hi Fred,

You need to Initialize the symbol to the persisted value before referencing it.

InitializationValue[isingarray] = 2 RandomInteger[{0, 1}, {100, 100}] - 1
Initialize[isingarray]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract