## 135 Reputation

13 years, 299 days

## Random integer from 0 to 100...

Maple

if you want a random interger between 0 and 100

what will be the command?

## From MATLAB code to Maple one...

Maple

this is the matlab is it possible to rewrite it in simple maple code

J = rand()+1e-10;

function [M, num, E] = ising(N,J)

B = 0;

M = []; % The total magnetic field of the system

E = []; % The total energy of the system

randTol = 0.1; % The tolerance, dampens the spin flip process

% First we generate a random initial configuration

spin = (-1).^(round(rand(N)));

% Then we let the system evolve for a fixed number of steps

for i=1:1000,

% Calculating the total spin of neighbouring cells

neighbours = circshift(spin, [ 0 1]) + ...

circshift(spin, [ 0 -1]) + ...

circshift(spin, [ 1 0]) + ...

circshift(spin, [-1 0]);

% Calculate the change in energy of flipping a spin

DeltaE = 2 * (J*(spin .* neighbours) + B*spin);

% Calculate the transition probabilities

p_trans = exp(-DeltaE);

% Decide which transitions will occur

transitions = (rand(N) < p_trans ).*(rand(N) < randTol) * -2 + 1;

% Perform the transitions

spin = spin .* transitions;

% Sum up our variables of interest

M = sum(sum(spin));

E = -sum(sum(DeltaE))/2; % Divide by two because of double counting

% Display the current state of the system (optional)

image((spin+1)*128);

xlabel(sprintf('J = %0.2f, M = %0.2f, E = %0.2f', J, M/N^2, E/N^2));

set(gca,'YTickLabel',[],'XTickLabel',[]);

axis square; colormap bone; drawnow;

end

% Count the number of clusters of 'spin up' states

[L, num] = bwlabel(spin == 1, 4);

#############################

## Is Ising a package?...

Maple

Hi all

Is Ising a package?

for i = 1:12000

%while (1),

% Choose a random value between 0 and 1 for the interaction strength

J = rand()+1e-10;

% Perform a simulation

[M, N, E] = ising2(n_grid, J);

% Records the results

Ms = [Ms M/(n_grid^2)];

Es = [Es E/(n_grid^2)];

Ns = [Ns N];

Js = [Js J];

i = i+1;

## Minimum points of 3D plots...

Maple

Hello,

How can I get the minimum point of (sin(x+y))

plot3d(sin(x+y), x=-1..1, y=-1..1);

## Bound of while loop...

Maple

Hello all,

here the programme I think there are some mistakes couldnot know where please any comment will be helpful:

# Firstly, set the size limit for the grid, which shall define how many
# points there are in both the vertical and horizontal direction
size=40;
# limit is a variable used to set an unobtainable upper bound
limit=size+1;
# x defined, starting at 1, and two other variables ud (upper diagonal) and
# dd (downward diagonal) begin at 0. All three are used to iterate through
# line creation

x=1;
ud=0;
dd=0;
# Iteration through x, using the line function to create a number of
# horizontal lines up to the limit point

while(x<(limit))
line([0, size], [x, x]);
x=x+1;
end

# Now iterating through the diagonals pointing upwards, using two sets of
# lines, both starting from the line going through the origin. The first
# iterates through the lines that pass through positive x values at y=0,
# the second iterates through the lines passing through negative x values
# at y=0
# ud must be increased by 2 each time to ensure that equilateral triangles
# are formed.

while(ud<(limit))
line([(ud), (size)], [0, (size-ud)]);
line([0, (size-ud)], [(ud), (size)]);
ud=ud+2;
end

# Similar to before, except this time iterating through downward pointing
# diagonals.

while(dd<(limit))
line([(dd), 0], [0, (dd)]);
line([(size), (dd)], [(dd), (size)]);
dd=dd+2;
end

# xvector and yvector set up as two vectors holding x and y co-ordinates of
# points respectively.

xvector = zeros(1, limit);
yvector = zeros(1, limit);

# Reinitiallising x and y values for iterative purposes.

x=0;
y=0.5;
n=1;

# The program now iterates through potential y values for the potential
# points. Then it tests the value of y to see what orientation the lattice
# is at that point, then randomly selects x values to enter, iterating
# between all the possible x values in the orientation before moving on to
# the next y value.

while(y<size)
if(mod(y,1)==0.5)
x=0.5;
while(x<size)
z=rand;
if(z>0.5)
xvector(n) =x;
yvector(n) =y;
n=n+1;
end
x=x+1;
end
elseif(mod(y,2)==1)
x=0;
while(x<size)
z=rand;
if(z>0.5)
xvector(n) =x;
yvector(n) =y;
n=n+1;
end
x=x+2;
end
else
x=1;
while(x<size)
z=rand;
if(z>0.5)
xvector(n) =x;
yvector(n) =y;
n=n+1;
end
x=x+2;
end
end
y=y+0.5;

end

# The program then enters the two co-ordinate vectors saved previously into
# the scatter function.

hold;
scatter(xvector, yvector);

 First 6 7 8 9 10 11 12 Page 8 of 13
﻿