Items tagged with random random Tagged Items Feed

Hei, I'm trying to create a random walk in the plane, with constant step length (=1) and the angle between two consecutive steps are decided by a probability density function. I just can't seem to find out how I should implement the density function into my worksheet.

The probability density function is: p(phi)=(1/4)*cos(phi/2), on the interval [-Pi,Pi].
And  I think i managed to do it by selecting a random angle, but don't know how to generate a random angle given this probability function. Any ideas? It'd be highly appreciated!



How to produce such a plot with Maple?
enter image description here

The difficulty is that the geom3d package does not include a command for a cylinder whereas
the plottools package has the cylinder command, but does not have a tool to determine whether
two random cylinders intersect.

Working on a code to create random lines. Here is the code: 

M:=1; N:=1500; R3:=rand(1..3): # M=lines, N=steps

for i from 1 to M do
X[i,0]:=0;
Y[i,0]:=0;
   for j from 0 to N do
   if j=1 then X[i,1]:=1; Y[i,1]:=0;
    elif j>1 then
      r:=R3();
        if r=1 then X[i,j]:=2*X[i,j-1]-X[i,j-2]; Y[i,j]:=2*Y[i,j-1]-Y[i,j-2]
        elif r=2 then X[i,j]:=X[i,j-1]+Y[i,j-1]-Y[i,j-2]; Y[i,j]:=Y[i,j-1]-X[i,j-1]+X[i,j-2];
        elif r=3 then X[i,j]:=X[i,j-1]-Y[i,j-1]+Y[i,j-2]; Y[i,j]:=Y[i,j-1]+X[i,j-1]-X[i,j-2];
      end if;
    end if;
   R[i,j]:=[X[i,j],Y[i,j]];
   K[i,j]:=[X[i,j],Y[i,j]];
  end do:
end do:

Now the code works fine. But I don't want the lines to cross its own path. I want it to stop if R[i,j]=R[i,k] for any 0<k<i-2 for j=0..N. What I have so far is:

for i from 1 to M do
  for j from 1 to 40 do
    R[i,j];
    for k from 1 to j-2 do
     if R[i,j]=K[i,k] then x:=j; print(b[i]=j); break; end if;
     L[i,j]:=R[i,j];
     end do;
   end do;
end do;

Now it works aswell, but it doesn't stop when it hits the crossing point. I want it to stop so i get one b[i]=j per M. So I need it to break two for loops so that it goes through i M times and stops everytime it reaches a crossing point

Hi,

I'm trying to create a code that allows me to model a random walk for 50 people. I'm using r[i]= {X[i],Y[i]} where i is the number of steps and r[i] the position in the i-th term.

I have created three possibilities:
2r[i]-r[i-1] - go stright forward

{x[i]+y[i]-y[i-1],y[i]-x[i]+x[i-1]} - turn right

{x[i]-y[i]+y[i-1],y[i]+x[i]-x[i-1]} - turn left

The first step I want them to make is to point (1,0) and from there I want them to take 1500 random steps.

M:=50; N:=1500; R3:=rand(1..3):

for i from 1 to M do
X[i,0]:=0;
Y[i,0]:=0;
R[i,0]:=[X[i,0],Y[i,0]];
for j from 1 to N do
R[i,j]:=[X[i,j],Y[i,j]];
if j=1 then X[i,1]:=1; Y[i,1]:=0;
elif j>1 then
r:=R3();
if r=1 then R[i,j]:=2*R[i,j]-[R[i,j-1];
elif r=2 then R[i,j]:=[X[i,j-1]+Y[i,j-1]-Y[i,j-2],Y[i,j-1]-X[i,j-1]+X[i,j-2]];
elif r=3 then R[i,j]:=[X[i,j-1]-Y[i,j-1]+Y[i,j-2],Y[i,j-1]+X[i,j-1]-X[i,j-2]];
end if;
end if;
end do:
end do:

 

The first and second step works, but from there it seems Maple is having trouble getting the correct digigts, because the formulas coming out are correct.

I have tried putting in different types of X, Y and R reads, but have gotten stuck. If someone could help me spot what this code is missing I would be very gratefull. I think Maple is just missing a way of reading X and Y but i might be wrong.

How can I generate some n-tuple random list of integers s.t. any component is between -30 and 50? For example if n=5 then four random of such 5-tuple are

[-1,2,8,7,9] , [0,-9,2,-3,-5] , [4,5,3,-8,-1] , [12, -5, 0, 6,8]

Perhaps the question is trivial, but I could not find the solution.

I am solving numerically an ODE (e.g., a simple harmonic oscillator) with the righthand side that contains a random part. For example it is

eq:=diff(a(t),t,t) + a(t) = (1+0.01*R(t))*cos(5*t);

where R(t) is a random function of t. How can I make such a function?

The naive attempt: 

eq:=diff(a(t),t,t) + a(t) = 3.*(1+0.1*rand()/1000000000000.)*cos(5.*t);


gave me a fixed (while random) value, e.g.

...

But, I need this coefficeint to be random each time step.

Any suggestions are very welcome!

 

 

 

Hi,

 

I have a problem with creating a function contains n-dimensional independent variables with random function .. The function looks like:

f(x)=sum(U[i] * abs(x[i])^i,i=1..n)

where U is a random between 0 and 1

 

For 1-dimensional problem, it will be like:

f(x)=U*abs(x)

The plot by MATLAB will be:

 

While, for 2-dimensional problem, it will be like:

f(x[1],x[2])=U[1]*abs(x[1]) - (-U[2]*abs(x[2])^2)

 

and the plot with MATLAB will be:

 

The MATLAB code is:

x1min=-5;
x1max=5;
x2min=-5;
x2max=5;
R=1000; % steps resolution
x1=x1min:(x1max-x1min)/R:x1max;
x2=x2min:(x2max-x2min)/R:x2max;

for j=1:length(x1)

    % For 1-dimensional plotting
    f1(j)=rand*abs(x1(j));

    % For 2-dimensional plotting
    for i=1:length(x2)
        fn(i)=f1(j)+rand*abs(x2(i))^2;
    end

    fn_tot(j,:)=fn;

end

figure(1)
plot(x1,f1);


figure(2)
meshc(x1,x2,fn_tot);

 

 

I have used Maple because of its great graphics and animation, and for the mathematical analysis capability. However, to animate the above problem for 1- and 2-dimensional problems, I always fail!

My attempt has been just successed to plot 1-dimensional problem (without animation) .. And it tooks long-time with many codes!

restart;

X := Statistics:-RandomVariable(('Uniform')(0, 1));
R := Statistics:-Sample(X, 1000);

Vect := abs(Vector[column]([seq(0 .. 10, 10/999)]));

V := `~`[`-`](Vect, 5);

with(LinearAlgebra);
Mat := Multiply(V, R);

with(ArrayTools);
f := ArrayTools:-Diagonal(Mat);

F := abs(f);

Axis := Transpose(V);

f5 := plot(Axis, F, style = line);

 

And finally I got the graph:

 

But the problem is:

How can I animate it? Maybe I need to express it with new Maple code?

How can I plot and animate it when n=2?

 

Thanks

I am trying to find the pdf of the inverse of a random variable X, that represents a distribution I defined. I currently have : 

with(Statistics):
T:=Distribution(PDF=(x->piecewise(0<x and x<1,1/4,3<x and x<5,3/8,0)));
X:=RandomVariable(T);
PDF(X,u);
CDF(X,u);
Y:=1/X;
T1:=RandomVariable(Y);

but this seems to be incorrect as I get a message saying T1:=RandomVariable(Y) is being passed a wrong argument. 

What is the right way to obtain the pdf of 1/X?

 

In Maple TA in blackboard I am creating an assignment. Each week a part of the assignment will be posted. I was wondering if it is possible to have the same random variables in differnet assignmemts. That way the students can use their prior work. 

So in week one the students will get a set of random variables. But in week two a new assignment is posted were I want the same variables to come up for each student. Is this possible? (all students will have their own unique set of variables)

Hi all,

 

I want to create a (set of) samples from an own distribution. The distribution itself is a normal distribution, but with some 'gaps', as shown below:

plot(exp(-(t-10)^2/(2*(0.5e-1*10)^2))*piecewise(t<9,0,t<9.9,1, t<10.1,0, t<11,1), t = 8.5 .. 11.5)

(It is supposed to represent the distribution of discrete resistor values (e.g. 10 ohms), where not only the values above the tolerance (e.g. 10%) are removed, but also those who can be sold as higher precision resistors (eg. 1%). The mean, lower tolerance and higher tolerance should be variables).

Because of the fact that in order to be able to use the Sample function, the PDF should be twice differentiable, the 'truncation' in the middle is realised using logistic functions.

I am able to create said distribution, and produce a DensityPlot, but when I try to take a (even a single) Sample from a RandomVariable from that distribution, Maple keeps calculating and no sample is produced.

GetDist := (mu, alpha, beta) -> Distribution(PDF = unapply(LotRPDF(t, mu, alpha, beta), t)):
T := GetDist(10, .1, 0.1e-1);
DensityPlot(T);
RandomR := RandomVariable(T):
Sample(RandomR, 1);

Where LotRPDF is the function depicted above, mu is the mean (10), alpha is the maximum tolerance (10%), , beta is the minimum tolerance (1%)

Am i overlooking something simple? Or is there a more fundamental error in my approach? I've added the maple sheet with more details.

RandomVariableSample.mw

 

Hi there, this is my first post in this forum. I hope you can help me with my problem :)

I've created a little program to solve a problem for my class. This is the first time, I wrote a program with Maple, so please don't laugh. 

I've posted the Maple code below:

 

restart; randomize():
with(plots): with(plottools): with(LinearAlgebra): with(Statistics): with(MTM):

s:={1=2, 3=2}:

 

Realisierung:=proc(np,volfrac)

local m, h, adresses, rndmAdrs, omega: omega:=Vector[row](np,s);

adresses:=Vector(np-nops(s));

h:=1;
for m from 1 to np do
if(omega[m]=0) then
adresses[h]:=m;
h:=h+1;
end if
od;

randomize():
rndmAdrs:=Shuffle(adresses);

for m from 1 to volfrac*np do
omega[rndmAdrs[m]]:=1
od:

for m from 1 to np -(volfrac*np+nops(s)) do
omega[rndmAdrs[m+int8(volfrac*np)]]:=2
od:

omega;

end:

 


RealMatrix:=proc(np,nr,volfrac)

local m, alle:

alle:=Matrix(nr,np); for m from 1 to nr do

randomize();

alle[m]:=Realisierung(np,volfrac); od;

alle;

end:

RealMatrix(5,5,0.4);

 

I used the Shuffle function from Statistics-package to randomly permutate the components in the Vector adresses. Which works fine. By setting Randomize(); I get randomly results vor this permutation, when I execute the whole worksheet.

But when the "Realisierung" procedure is called in the for loop of the "RealMatrix" procedure, always the same Permutation is calculated.

This leads to the fact, that every row in my matrix looks the same.
Like in the example

2 1 2 2 1
2 1 2 2 1
2 1 2 2 1
2 1 2 2 1
2 1 2 2 1

but the lines should be randmly like

2 1 2 2 1
2 2 2 1 1
2 1 2 1 2
2 1 2 2 1
.....

 

Obvioulsy the problem is in the randomize()-command. I tried to place it directly after "restart" and directly before the Shuffling is executed.
But I had no succes. 

Maybe one of you can help me?
Would be great!
Thanks

 

 

 

 

 

 

Dear all;

nice to speak with you.

complete a table randomly by positive three-digit numbers and display only the symmetrical numbers.

 

Thanks

Hello,

I am trying to make c (0.001<=c<=0.02) a random value at each time step.But with my code c is choosing randomly from the interval then solveing the equation for fixed c at each time step.

How can I mack c a diffrent random value at each time step?

This is my code:

> with(DEtools); with(plots);
>
> Ra := RandomTools:-Generate(distribution(Uniform(0.001, 0.02))); c := Ra;
> f := .1;
>
> eq := diff(X(t), t) = 1-f-c*X(t);
>
> init := X(0) = 100;
>
> sol := dsolve({eq, init}, {X(t)}, range = 0 .. 100, numeric);
>
> odeplot(sol, [[t, X(t)]], t = 0 .. 100);

 

Thank you

M:=Array([[a+2*b,b],[x1+y1,z1+z2]]);
pars:=indets(M);
npars:=numelems(pars);

myRand:=RandomTools[Generate](float(range=-3..3),makeproc=true):

set1:={seq(pars[i]=myRand(),i=1..npars)};
numM:=subs(set1,M);
LinearAlgebra:-Rank(numM);

is there a way to make sure that the random values generated from myRand(), subs into M, to make sure that each cell of M is between 0 and 1?

Basically, what I need is being able to simulate some values, subject to each cell of M is between 0 and 1, and find the rank of M. I want to do that efficiently 20 times (or more possibly). Those values that make the cells out of 0 and 1 do not count as 1 of the 20 simulations.

 

Thanks,

 

casper

 

 

Hello everybody,

 

I find a answer on that subject at this link: http://www.mapleprimes.com/maplesoftblog/95508-Monte-Carlo-Pi

But for starting easy, I try this:

with(RandomTools[MersenneTwister]);
directpi := proc (n)
local i, x, y, N;
N := 0;
Digits := 2;
for i to n do
x := GenerateFloat();
y := GenerateFloat();
if x^2+y^2 < 1 then
N := N+1:
end if:
end do:
N;
end proc;


evalf(directpi(4000)/(1000.0), 4);

                             3.176

I would like to know if this code is appropriate and if it is possible to have a random number between -1 to 1 so it will be easier to plot the points in the square with the circle inside.

 

Thank you.

--------------------------------------
Mario Lemelin
Maple 18 Ubuntu 13.10 - 64 bits
Maple 18 Win 7 - 64 bits messagerie : mario.lemelin@cgocable.ca téléphone :  (819) 376-0987
1 2 3 4 5 Page 1 of 5