Items tagged with random

How do I genereate random negative numbers?

 

when i put a minus sign in the rand-function i get an error.

 

I need to for example generate a random number between -r and r, where r is the input

 

 

If a particle that moves in only one dimension is subject to a force Fi between the time

steps ti and ti+1, the velocity vi and position xi of the particle is:

 

v[i] := v[i − 1] +(1/m)*F[i]*Δt

x[i] := x[i − 1] + 0.5 (v[i − 1] + v[i])                   

 

Use the mean of v between ti and ti+1 when updating xi, since the value may change

a lot from step to step. In the subsequent, we set the mass m = 1 and the time steps

are Δt = 1, since we could absorb m and Δt in the expression for the force Fi anyway.

 

Write a procedure that computes xi and vi for a particle subject to random forces Fi,

uniformly distributed on the interval [-0.5..0.5].

 

I`ve written a procedure that generates random forces (F[i]) in the given interval. How can I write a for – procedure that computes xi and vi ?

Hi

I need help to write a procedure that uses Maple`s built-in rand() - function to generate uniform random floating point numbers between -r and r, where r is an input parameter of the procedure.

>M:=600;

>R1:=rand(0..1):   R2:=() -> 2*R1()-1:       
>for i from 1 to M do
    f[i]:=R2()*rand()/10.^12:
  end do:

With this procedure I get random floating point numbers (+/-), but I can`t figure out how to generate numbers between +/- a parameter (in this case r).

If anyone could help me understand how to get this to work I would be very gratefull.

I have made an algorithm for producing random walks (only possible to walk one step to either direction except downwards(EDIT: It is possible to go downwards, but it has to be when making a turn to the right or left). The walks are determined by the rand function:

R3:=rand(1..3): (1: go straight on; 2: turn right; 3: turn left)
M:=15; N:=1500;

 

Randwalk3:=proc(R3)
  local i,j,r,X,Y,L;
  for j from 1 to M do
    X[0,j]:=0;                                # Initialization
    Y[0,j]:=0;
    X[1,j]:=1;                                # The first step should still be taken to the point (1,0)
    Y[1,j]:=0;
    for i from 2 to N do
      r:=R3();
      if r=1 then X[i,j]:=2*X[i-1,j]-X[i-2,j]; Y[i,j]:=2*Y[i-1,j]-Y[i-2,j];                   # go straight on
      elif r=2 then X[i,j]:=X[i-1,j]+Y[i-1,j]-Y[i-2,j]; Y[i,j]:=Y[i-1,j]-X[i-1,j]+X[i-2,j];    # turn right
      else X[i,j]:=X[i-1,j]-Y[i-1,j]+Y[i-2,j]; Y[i,j]:=Y[i-1,j]+X[i-1,j]-X[i-2,j];             # turn left
      end if;
      if (X[i,j]=X[j,j] and Y[i,j]=Y[j,j]) then L[j]:=i; break; end if; (This is wrong)
    end do;
  end do:
  return [X,Y,L];
end proc:
 

The question from is like this:
Modify the algorithm such that it stops at r[i] if r[i] = r[j] for any 0 <= j <= i-2. r=(xi,yi). M is the number of random walks and N is the number of steps. The length of the paths should be stored in L[m] (m=1..M). How do I implement the if-test correctly?

Hi All,

I have a fucntion f(x,y,z) = exp(-x^2 -y^2 - z^4) and would like to plot the probabity density in real space. One method would be to randomly sample points in a grid based on f(x,y,z). The function f(x,y,z) is clearly peaked around x=y=z=0, so you would expect many points to lie around there. So the plot would look like a clump near (0,0,0) which gets less dense away from (0,0,0).

In the worksheet below, I sampled points from the Uniform distribution to file in the 3d-plot. I would like these points to be sampled from f instead, but am not sure how to do this.

Any help is appreciated,

restart;

with(Statistics):

R := 10; # x-axis size
N := 100; # Number f points to sample

10

 

100

(1)

# Unnormalized Probability distrubution

f := (x,y,z) -> exp(-x^2 -y^2 - z^2);

proc (x, y, z) options operator, arrow; exp(-x^2-y^2-z^2) end proc

(2)

# Clearly f is peaked at (0,0,0) and decays. Therefore I want a plot a lot of points near (0,0,0), and fewer points away from (0,0,0)

plot3d(f(x,y,0), x = -1..1, y = -1..1);

 

X := Sample(Uniform(-R, R), N):

Y := Sample(Uniform(-R, R), N):
Z := Sample(Uniform(-R, R), N):
XYZ := Matrix([[X], [Y], [Z]])^%T;

XYZ := Matrix(100, 3, {(1, 1) = 9.758694699049908, (1, 2) = 2.6237746853802246, (1, 3) = 5.657441459582465, (2, 1) = -6.591359538862333, (2, 2) = -2.89852696242302, (2, 3) = 3.875752299737945, (3, 1) = -4.844154988559739, (3, 2) = 9.940065432132954, (3, 3) = -9.803954954738758, (4, 1) = -2.0640136273371272, (4, 2) = -5.516570020337457, (4, 3) = 6.864266760210192, (5, 1) = -8.52010460846124, (5, 2) = 3.049021459372298, (5, 3) = 8.446639955925516, (6, 1) = 3.68192133924018, (6, 2) = 2.099812838165187, (6, 3) = 5.41908441347849, (7, 1) = -1.9522333460767616, (7, 2) = -2.2550913703373006, (7, 3) = -9.146802881299026, (8, 1) = 9.65670402787902, (8, 2) = -7.156256814189918, (8, 3) = -2.4362772589956228, (9, 1) = -1.9563202955503058, (9, 2) = -9.497300285795937, (9, 3) = 4.086792489667353, (10, 1) = 2.4134389439915687, (10, 2) = -1.5777549246951743, (10, 3) = 4.590260910092939, (11, 1) = -6.912603890414553, (11, 2) = -6.317994211449776, (11, 3) = -5.514458586709711, (12, 1) = -2.3730959111105605, (12, 2) = 4.515505349389063, (12, 3) = -4.618905364532699, (13, 1) = -6.777320563012783, (13, 2) = -2.592746269696038, (13, 3) = 3.4606233000823785, (14, 1) = 5.162248626548372, (14, 2) = 6.831201749364123, (14, 3) = -.45015604546277466, (15, 1) = 7.422222438307784, (15, 2) = 4.684593823866264, (15, 3) = 2.4743282533488493, (16, 1) = -2.9844651022821473, (16, 2) = 1.4205174564875769, (16, 3) = -5.2711013471817925, (17, 1) = 3.710714174950745, (17, 2) = -6.462898847493945, (17, 3) = -6.457524910033669, (18, 1) = -4.117027324643008, (18, 2) = 9.147680451914468, (18, 3) = 6.592867713951691, (19, 1) = .6125860771377116, (19, 2) = -4.693559276141599, (19, 3) = 5.338433358705297, (20, 1) = 6.648467725703679, (20, 2) = 8.491617904792019, (20, 3) = 8.68956546236539, (21, 1) = 1.9498038374515865, (21, 2) = -5.52459190605918, (21, 3) = -7.842221898312729, (22, 1) = -3.2937733858950775, (22, 2) = -2.5287238471471003, (22, 3) = -6.355449887978885, (23, 1) = -4.015499533337867, (23, 2) = -8.249993008468286, (23, 3) = -8.01809435155083, (24, 1) = -.9481491686135186, (24, 2) = 2.802330964934301, (24, 3) = -.20472396153106232, (25, 1) = -1.5470869355907517, (25, 2) = -6.387662244937832, (25, 3) = -6.13509339062259, (26, 1) = -2.8078736405552878, (26, 2) = -9.098977850528517, (26, 3) = 7.917831475851365, (27, 1) = 1.1663839973859425, (27, 2) = 4.4634695836619045, (27, 3) = -8.01820700636371, (28, 1) = 4.850907314038782, (28, 2) = -3.051247088364198, (28, 3) = -9.116688564746777, (29, 1) = -1.5133043274861873, (29, 2) = 3.2123364900580764, (29, 3) = 1.145903116095237, (30, 1) = -1.4128842284758996, (30, 2) = -2.322627978560572, (30, 3) = 5.449901343752481, (31, 1) = -7.502544825603743, (31, 2) = 2.5469300488693403, (31, 3) = -3.7611988500746225, (32, 1) = -9.511319678992521, (32, 2) = -9.567003707393871, (32, 3) = -6.420350413713298, (33, 1) = -4.196294697385456, (33, 2) = 8.21139977046057, (33, 3) = -3.220886435045635, (34, 1) = -3.6495883420154733, (34, 2) = 6.011173125576221, (34, 3) = -5.7970872591289595, (35, 1) = 3.0738026793295035, (35, 2) = 4.916949686854423, (35, 3) = .20305039530500402, (36, 1) = 9.138718481413683, (36, 2) = 6.262256272215215, (36, 3) = 8.127286465304294, (37, 1) = 8.71461745569761, (37, 2) = -2.3338736274894156, (37, 3) = 2.578478773046358, (38, 1) = -.8422733229126642, (38, 2) = 2.345584646328984, (38, 3) = -7.969322223753757, (39, 1) = -5.190432063358308, (39, 2) = 1.5098971940562773, (39, 3) = -2.1829049454729077, (40, 1) = 5.277958885729566, (40, 2) = .6010340953003119, (40, 3) = -8.907667695526849, (41, 1) = 5.186547662621926, (41, 2) = -4.498604883561299, (41, 3) = 0.25658264064304603e-1, (42, 1) = 4.812961299572285, (42, 2) = -5.027420806760592, (42, 3) = -1.3655765623150558, (43, 1) = 4.87376682974652, (43, 2) = -.9672245909605444, (43, 3) = 9.951206990243783, (44, 1) = -7.881591665344693, (44, 2) = -5.445743479469048, (44, 3) = 6.232051619906457, (45, 1) = 3.631208609406313, (45, 2) = 6.0889916722614, (45, 3) = -.2869666020396462, (46, 1) = -.7347884281256167, (46, 2) = 9.722084837919404, (46, 3) = 7.888955111347865, (47, 1) = -5.756735894901313, (47, 2) = -9.4001609946122, (47, 3) = -7.249068104658704, (48, 1) = -8.029625246237833, (48, 2) = .7132838133447539, (48, 3) = -2.1999017110942916, (49, 1) = 6.471489478556769, (49, 2) = -8.258455601982153, (49, 3) = 8.547124499962496, (50, 1) = -6.499805252358408, (50, 2) = 6.04182881111608, (50, 3) = 8.34987664832234, (51, 1) = -6.728601804300136, (51, 2) = 9.782898194006798, (51, 3) = 4.271480231886315, (52, 1) = 3.319744328222212, (52, 2) = -8.661074832044998, (52, 3) = 2.3667476724388, (53, 1) = 7.887787507084855, (53, 2) = 8.787967237690697, (53, 3) = -3.1342421951730914, (54, 1) = .33116416702540796, (54, 2) = -9.636449327266085, (54, 3) = 8.720546533795396, (55, 1) = 4.054046139009506, (55, 2) = 3.6767722749271066, (55, 3) = -7.504519186790148, (56, 1) = -6.9281924676119955, (56, 2) = 5.674729601664373, (56, 3) = 4.611707230114142, (57, 1) = 9.069141397724955, (57, 2) = .6827513576545652, (57, 3) = 2.929548648516276, (58, 1) = .8176816248295289, (58, 2) = 7.7071890186228345, (58, 3) = 6.663039713385899, (59, 1) = 3.594677964209339, (59, 2) = 7.980097978122803, (59, 3) = -2.034355435624491, (60, 1) = -9.268739639030944, (60, 2) = 2.518752521609917, (60, 3) = 4.9964441872127185, (61, 1) = 6.184077025875865, (61, 2) = -7.242620151748835, (61, 3) = 6.70441020956261, (62, 1) = 4.972377435523942, (62, 2) = -5.6439681257575085, (62, 3) = -3.5507920527548116, (63, 1) = -7.596259640258387, (63, 2) = -6.357178482191326, (63, 3) = 1.0452323371671, (64, 1) = .5009032952521757, (64, 2) = -9.163602720540913, (64, 3) = 9.582582648677842, (65, 1) = -3.483327424735016, (65, 2) = -7.86116682899586, (65, 3) = .9861706603660547, (66, 1) = .9289887980613702, (66, 2) = 2.328869701713703, (66, 3) = -3.391527807867945, (67, 1) = -2.0223849523360204, (67, 2) = 8.793220203221335, (67, 3) = 2.389431103555598, (68, 1) = -1.6981322677390676, (68, 2) = -2.910885380653423, (68, 3) = -2.7872685799559456, (69, 1) = -6.3852447949041125, (69, 2) = -1.7874181988097213, (69, 3) = 5.130190870038886, (70, 1) = -4.892265190238985, (70, 2) = 9.68698833968903, (70, 3) = -1.7219850261962062, (71, 1) = -9.589284506836309, (71, 2) = 8.911583780705254, (71, 3) = -.15309791230124503, (72, 1) = 8.473512252408145, (72, 2) = 3.532893568670783, (72, 3) = 3.8948646626522017, (73, 1) = 3.073997780165058, (73, 2) = 9.766045246265726, (73, 3) = 9.454677701595681, (74, 1) = 8.652271440971283, (74, 2) = 5.336627744331885, (74, 3) = -3.4449007901318645, (75, 1) = -6.729752629449488, (75, 2) = -3.2660147121704775, (75, 3) = 6.756063661571513, (76, 1) = 8.42194511784395, (76, 2) = 3.2476372079896247, (76, 3) = 4.781444545470562, (77, 1) = 5.893157707775064, (77, 2) = -5.116694264194415, (77, 3) = 9.083489127590862, (78, 1) = 1.5478839341329742, (78, 2) = -4.089854983368064, (78, 3) = -9.361547409920432, (79, 1) = -1.1992880847949277, (79, 2) = 3.6035674246100413, (79, 3) = -2.8626202763491593, (80, 1) = -4.8477252657512455, (80, 2) = .5569366083759579, (80, 3) = 3.25307668574429, (81, 1) = 5.038927877349, (81, 2) = -1.7681297318493083, (81, 3) = -4.369968817030188, (82, 1) = -5.426610357889972, (82, 2) = 2.0527643607279433, (82, 3) = -5.392338653650725, (83, 1) = -8.716258252162028, (83, 2) = 5.010401118474713, (83, 3) = 4.222571023606502, (84, 1) = 5.346590215531489, (84, 2) = 1.6706634852391726, (84, 3) = 2.4914583398661705, (85, 1) = 3.4240437071307106, (85, 2) = 1.0358502987193496, (85, 3) = 1.8121730583927196, (86, 1) = 4.304250295716802, (86, 2) = 1.6714123751542882, (86, 3) = 3.2087593262520375, (87, 1) = 2.8412165686770443, (87, 2) = .236398399169504, (87, 3) = -9.04890653772268, (88, 1) = -1.6190341275023385, (88, 2) = -8.348145460026013, (88, 3) = -3.0243038297988223, (89, 1) = -2.184758355916509, (89, 2) = 4.391402697189795, (89, 3) = -.9731883928851364, (90, 1) = 6.322802057506454, (90, 2) = 9.923122225937387, (90, 3) = -5.181900057597786, (91, 1) = -3.6514427268830074, (91, 2) = -2.909313900861563, (91, 3) = 4.300900265923531, (92, 1) = 6.290795458013026, (92, 2) = 9.425176303668113, (92, 3) = 7.123645840125757, (93, 1) = 5.7814702987791655, (93, 2) = -3.071024773992807, (93, 3) = -4.369846097628933, (94, 1) = 7.045277806876914, (94, 2) = 7.730877235206126, (94, 3) = 4.621016594474829, (95, 1) = .11273235143512395, (95, 2) = -.9061027001618438, (95, 3) = -7.244742149609673, (96, 1) = 2.7132277772275373, (96, 2) = -1.7314542195836946, (96, 3) = 6.734455634994351, (97, 1) = 9.017888307562703, (97, 2) = -5.645358632853991, (97, 3) = -7.2279656851528, (98, 1) = -1.1207168996237922, (98, 2) = -7.486908252747475, (98, 3) = 1.7641877077898727, (99, 1) = -8.799623604410481, (99, 2) = -3.821708128663694, (99, 3) = -2.6768639909012437, (100, 1) = 7.334997939986373, (100, 2) = 4.522088633296637, (100, 3) = 6.135190893222113}, datatype = float[8])

(3)

ScatterPlot3D(XYZ, color = blue, symbolsize = 20);

 

 

 

 

 


 

Download Sample_Test.m

 

Hi everybody,

I would like to define a function with random values to be used in pdsolve (numeric) as a initial condition.

Any help?

Thanks,

Javier

Dear Community,

How could I specify a list of random colors using some kind of an RGB function, which then could be used in another command for coloring? I think of something like this:

myColors := [ seq( RGB ( [rint(0,255) , rint(0,255) , rint(0,255)] ) , j = 1 .. 20 ) ] :

which does not work of course :-)  This should produce me a list of 20 random colors.  What would be the right RGB color function?

Tx for the kind help in advance

best regards

Andras

To gererate a random initail cofigration -1 or 1

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

 

for i=1:1000,

 

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

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

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

circshift(spin, [-1 0]);

how to do this in maple?

if you want a random interger between 0 and 100

what will be the command?

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;

of a (concrete/general) triangle, making use of Maple tools in an efficient way?  Mathematica applies the barycentric coordinates and the Dirichlet distribution to this end. More generally, how to efficiently choose a random point in a given bounded region?

Coding in key generation of RSA Cryptosystem

message :=123456;

u := nextprime(RandomTools[Generate](integer(range = 10^100 .. 10^(110-1))));

v := nextprime(RandomTools[Generate](integer(range = 10^100 .. 10^(110-1))));

N := u*v;

phi := (u-1)*(v-1);

In RSA cryptosystem, the encryption or decryption of message only can be existed between range 1<=message<=N. This means that if the value of message bigger than N value then we can't get back the original value when performing decryption.Thus, wanna to ask that how can we create a coding so that the system will recognise the random integer u and v whether lie between range 1<=message<=N, means wanna crete a coding that if  N>=message then it will continue to the phi step whereas if message>=then the system need to regenerate the u and v until it satisfy the condition  1<=message<=N .Thus please help as i am a beginner in Maple.Thanks.

May I know any command can help to random selected a position in a group of bit number then flip that number but with condition after convert to bytes the number cannot be more than 7?

For example,

I have integer 3, i convert to binary become 0000011

then i need a command to random select a position to flip and only one bit can be flipped.

After that the group of flipped number will convert back to decimal, but total value cannot more than 7? any command can solve?  Thank you. 

How to generate a random normal distribution of points around the point [3,15] for example?

Wanna ask that how to make maple program to select a random binary number in base 2.

For example, suppose that we have a value 11101100(8 bit which in base 2),then how to let Maple to select a binary number randomly and the binary bit of the random number always shorter than the previous then sum it together?

For example the program will select 1101101(7-bit) and sum it together(11101100+1101101=101011001,in base 2)

Can somebody help me thanks.

1 2 3 4 5 6 Page 1 of 6