Im trying to run the following code, which I have translated from Matlab. I created a for loop nested inside another for loop. mW
is a matrix, and vMuTilde
is a vector.
i.e.
dw1 = 3; mW = {{1, 0, 1}, {1, 2, 1}, {1, 1, 1}}; vMuTilde = {1, 2, 1};
I got
set:write Tag Times is protected
so I tried adding Clear[v]
and Clear[p]
thinking it might be related to the fact that I use this variables again and again.
Now I still get this error, and in addition I also get
"$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of ...".
Now it looks like I'm in an infinite loop, since I don't get to the "0"
printed at the end.
Thanks a lot T
For[r=1, r<=dw1,r++,
Clear[v]
v = mW[[r]];
mu = vMuTilde[[r]];
Print[mu];
For[rr=1, rr<=r-1,rr++,
Clear[p]
p = v*mW[[rr]];
v = v - p*mW[[rr]];
mu = mu - p*vMuTilde[[rr]];
]
norm = Norma[v];
Print["dd"];
mW[[r]] = v / norm;
vMuTilde[[r]] = mu / norm;
]
Print[0]
dw1
is less thanMin[Length[mW], Length[vMuTilde]]
? $\endgroup$dw1 = Dimensions[mW][[1]];
in the line before the loop $\endgroup$