q41b3

20 Reputation

4 Badges

13 years, 222 days

MaplePrimes Activity


These are questions asked by q41b3

I am really not good at writing the code. The code was from the book (Stochastic process with maple).

It does not seem to generate the different plots when I run the code.

Also the last added code was from the book but it shows error.

Thank you for the help in advance. (My English also is not good.)
 

> 

restart

> 

with(stats)

> 

with(plots)

> 

RandWalk := proc (N, p, q, sa, sb, M) local A, B, r, PA, PC, PB, state, step, path; A := -N; B := N; r := 1-p-q; PA := empirical[0., sa, 1-sa]; PC := empirical[q, r, p]; PB := empirical[1-sb, sb, 0.]; state := 0; path := state; to M do if A < state and state < B then step := trunc(stats[random, PC](1))-2 elif state = A then step := trunc(stats[random, PA](1))-2 elif state = B then step := trunc(stats[random, PB](1))-2 end if; state := state+step; path := path, state end do; plots[pointplot]([seq([i, path[i]], i = 1 .. nops([path]))], axes = BOXED) end proc

> 

RandWalk(3, .5, .5, .8, .8, 20)

 
> 

plots[display]([seq(RandomWalk(10, .45, .5, .8, 300), k = 1 .. 4)], insequence = true); plots[display](%)

Error, (in plots:-display) cannot make plot structure from object with name RandomWalk

 

 
> 

``


 

Download randomWalk.mw
 

> 

restart

> 

with(stats)

> 

with(plots)

> 

RandWalk := proc (N, p, q, sa, sb, M) local A, B, r, PA, PC, PB, state, step, path; A := -N; B := N; r := 1-p-q; PA := empirical[0., sa, 1-sa]; PC := empirical[q, r, p]; PB := empirical[1-sb, sb, 0.]; state := 0; path := state; to M do if A < state and state < B then step := trunc(stats[random, PC](1))-2 elif state = A then step := trunc(stats[random, PA](1))-2 elif state = B then step := trunc(stats[random, PB](1))-2 end if; state := state+step; path := path, state end do; plots[pointplot]([seq([i, path[i]], i = 1 .. nops([path]))], axes = BOXED) end proc

> 

RandWalk(3, .5, .5, .8, .8, 20)

 
> 

plots[display]([seq(RandomWalk(10, .45, .5, .8, 300), k = 1 .. 4)], insequence = true); plots[display](%)

Error, (in plots:-display) cannot make plot structure from object with name RandomWalk

 

 
> 

``


 

Download randomWalk.mw

 


Could you help me?

> 

restart

> 

with(stats)

> 

with(plots)

> 

"RandWalk :=proc(N,p,q,sa,sb,M)  local A,B,r,PA,PC,PB, state,step,path:  A:=-N: B:=N: r:=1-p-q:  PA:=empirical[0.,sa,1-sa]:  PC:= empirical[q,r,p]:  PB := empirical[1-sb,sb,0.]:  state:=0: path:=state:  from 1 to M do  if (A< state and state <B) then step:=trunc(stats[random, PC](1))-2:  else if state =A then step:= trunc(stats[random,PA](1))-2:  else if state =B then step:= trunc(stats[random,PB](1))-2:  end if:  state := state + step:  path := path,state:  end do:  plots[pointplot]([seq([i,path[i]],i=1..nops([path]))],axes=BOXED):  end proc:"

Error, unterminated procedure

"RandWalk :=proc(N,p,q,sa,sb,M) local A,B,r,PA,PC,PB, state,step,path:  A:=-N: B:=N: r:=1-p-q:  PA:=empirical[0.,sa,1-sa]:  PC:= empirical[q,r,p]:  PB := empirical[1-sb,sb,0.]:  state:=0: path:=state:  from 1 to M do  if (A< state and state <B) then step:=trunc(stats[random, PC](1))-2:  else if state =A then step:= trunc(stats[random,PA](1))-2:  else if state =B then step:= trunc(stats[random,PB](1))-2:  end if:  state := state + step:  path := path,state:  end do:  plots[pointplot]([seq([i,path[i]],i=1..nops([path]))],axes=BOXED):  end proc:"

 
> 

``


 

Download randomWalk.mw
 

> 

restart

> 

with(stats)

> 

with(plots)

> 

"RandWalk :=proc(N,p,q,sa,sb,M)  local A,B,r,PA,PC,PB, state,step,path:  A:=-N: B:=N: r:=1-p-q:  PA:=empirical[0.,sa,1-sa]:  PC:= empirical[q,r,p]:  PB := empirical[1-sb,sb,0.]:  state:=0: path:=state:  from 1 to M do  if (A< state and state <B) then step:=trunc(stats[random, PC](1))-2:  else if state =A then step:= trunc(stats[random,PA](1))-2:  else if state =B then step:= trunc(stats[random,PB](1))-2:  end if:  state := state + step:  path := path,state:  end do:  plots[pointplot]([seq([i,path[i]],i=1..nops([path]))],axes=BOXED):  end proc:"

Error, unterminated procedure

"RandWalk :=proc(N,p,q,sa,sb,M) local A,B,r,PA,PC,PB, state,step,path:  A:=-N: B:=N: r:=1-p-q:  PA:=empirical[0.,sa,1-sa]:  PC:= empirical[q,r,p]:  PB := empirical[1-sb,sb,0.]:  state:=0: path:=state:  from 1 to M do  if (A< state and state <B) then step:=trunc(stats[random, PC](1))-2:  else if state =A then step:= trunc(stats[random,PA](1))-2:  else if state =B then step:= trunc(stats[random,PB](1))-2:  end if:  state := state + step:  path := path,state:  end do:  plots[pointplot]([seq([i,path[i]],i=1..nops([path]))],axes=BOXED):  end proc:"

 
> 

``


 

Download randomWalk.mw

 

restart; with(stats); with(plots); RandWalk :=proc(N,p,q,sa,sb,M) local A,B,r,PA,PC,PB, state,step,path: A:=-N: B:=N: r:=1-p-q: PA:=empirical[0.,sa,1-sa]: PC:= empirical[q,r,p]: PB := empirical[1-sb,sb,0.]: state:=0: path:=state: from 1 to M do if (A< state and state

1 2 Page 2 of 2