AlphaGreen

10 Reputation

One Badge

8 years, 240 days

MaplePrimes Activity


These are questions asked by AlphaGreen

So below is a calculation im trying to create, but it just tells me there is an unexpected IF error, and returns me to the third For line. I have tried it straight and as a procedure but i just cant seem to get it to work. Any ideas or tweaks to make this work would be much appreciated. All of the other variables I've named work in their respective lines of code, which I have left out as it is long as it is!


ComlexAlgorithm:= proc(L)
local N, j, kf, o, DeltaMag, DeltaBond;
global NConfig, Configz1, Col, Row, OldConfig, NewConfig, NewTable;

# Set Delta values to zero.
DeltaMag:=0:
DeltaBond:=0:

# Creates loops to loop through the correct changes in values i.e. Add -1, then 1 to first point, move across each point one by one, repeat from the beginning for each configuration then repeat whole process for the amount of rows.
printlevel:=4:
for N from -1 to 1 by 2 do
   for j from 1 to Col do
      for w from 0 to NConfig-1 do   
         for o from 1 to Row do

# Calculate DeltaMag.
if N=-1 then DeltaMag:=DeltaMag+1 else DeltaMag:=DeltaMag-1
end if:

# Calculate all relevant bonds i.e. 3 values for DeltaMag, except at "corner" lattice points where there is only 2 bonds.
if N= Configz1[w](o, j) then DeltaBond:= DeltaBond-1 else DeltaBond:= DeltaBond+1
end if:

if j-1>1 then
   if N <> Configz1[w](o, j+1) then DeltaBond:= DeltaBond+1
      if N = Configz1[w](o, j+1) then DeltaBond:= DeltaBond-1
else DeltaBond:= DeltaBond
end if:
end if:
end if:

if j+1<Col then
   if N <> Configz1[w](o, j+1) then DeltaBond:= DeltaBond+1
      if N = Configz1[w](o, j+1) then DeltaBond:= DeltaBond-1
else DeltaBond:= DeltaBond
end if:
end if:
end if:

# Calculate if, and by what degree, conifguration number changes using 2^(j-1) which is the arithmetric series for binary. Changes only occur when "incoming" spin is different.
if N= -1 then
   if Configz1[w](o, j) <> N then NewConfig[w]:= OldConfig[w-(2^(j-1))] 
else NewConfig[w]:= OldConfig[w]
end if:
end if:

if N= 1 then
   if Configz1[kf](o, j) <> N then NewConfig[w]:= OldConfig[w+(2^(j-1))] 
else NewConfig[kf]:= OldConfig[w]
end if:
end if:

NewTable[kf]:= [NewConfig[w], BondEnergy(w)+DeltaBond, MagEnergy(w)+DeltaMag];

# Set Delta values to zero to finsh.
DeltaMag:=0:
DeltaBond:=0:

end do:
end do:
end do:
end do:
end proc:

Hi, so I have few problems here. I need to;

Create a MxN Matrix/Lattice, where N and M can be any positive integer, that contains a random selection of -1/1s at each entry.

Need to sum every entry, then multiply by -1 to find “H”.

Need to multiply each neighbour to find its bond energy, so if it’s the same you get 1 else -1, but only its direct neighbours once, so if it was a 2x2 matrix there would be only 4 values and then sum them.

I don’t seem to be able to set up the code so that it does it for any size matrix, as I only know how to write it out basic for a 2x2. Also, not so important, but I wanted to know if could create a loop that would find every iteration of possible setups i.e. for a 2x1 you can have 1.1, -1.1, 1.-1, -1.-1. And then give the solutions outlined earlier for each of the the possibilities [There being 2MxN ]

Cheers in advance.

Page 1 of 1