ber9erud

15 Reputation

5 Badges

11 years, 114 days

MaplePrimes Activity


These are replies submitted by ber9erud

I just found out the the other reason the substitution wasn't working was because the directories for the two worksheets turned out to be different.

@acer wow, thanks a bunch.  So was it as if I was greating a second p variable by making the assumption locally within the procedure?

@acer 

No reason for using the deprecated array, I've switched it now.  Here's the procedure P_Chain


### Generates chain adjaceny matrix for parametrized chains. Vector should be of form V[i]:=+-1,0, where: ###
# -1 represents p <- ith node -> 1-p
# +1 represents 1-p <- ith node -> p
# 0 represents 1/2 <- ith node -> 1/2
# Vector of length N will generate chain of length N. First and last entries will be ignored as they are given by AdjM[1,2]=1, and AdjM[n,n-1]=1
P_Chain:=proc(V::Vector)::Matrix; description "Input: Vector", "Output: Matrix", "Generates chain adjaceny matrix given valid Vector of p<->1-p weighted vertices. Vector should be of form V[i]:=+-1,0, where:",
" -1 represents p <- ith node -> 1-p ",
" +1 represents 1-p <- ith node -> p ",
" 0 represents 1/2 <- ith node -> 1/2 ", "Vector of length N will generate chain of length N. First and last entries will be ignored as they are given by AdjM[1,2]=1, and AdjM[n,n-1]=1";
uses LinearAlgebra;
local i, j, N, AdjM, vlist;
global p;
assume(p, real);
vlist:=convert(V, list);
N:=nops(vlist);
AdjM:=Matrix(1..N, 1..N, fill=0);
AdjM[1,2]:=1; AdjM[N,N-1]:=1;
for i from 2 to N-1 do
if vlist[i]=1 then
AdjM[i, i-1]:=1-p;
AdjM[i, i+1]:=p;
elif vlist[i]=-1 then
AdjM[i, i-1]:=p;
AdjM[i, i+1]:=1-p;
elif vlist[i]=0 then
AdjM[i, i-1]:=1/2;
AdjM[i, i+1]:=1/2;
else error "invalid vector parameter or length. All entries must be one of {0,1,-1}";
end if;
end do;
return AdjM;
end proc:

It worked, thanks!

It worked, thanks!

Thanks.  I can't find a lot of information describing the behaviour of escaped variables, but I guess the point is that its best to avoid them.

Thanks.  I can't find a lot of information describing the behaviour of escaped variables, but I guess the point is that its best to avoid them.

Page 1 of 1