I have a square matrix m
to which I want to assign new values into its diagonal. For example,
m={
{20, 24, 33, 36, 34},
{39, 13, 15, 30, 30},
{18, 17, 16, 28, 27},
{39, 35, 33, 32, 37},
{30, 21, 22, 10, 23}
}
I want to change the diagonal elements into some negative numbers:
Table[
m[[i, i]] = RandomInteger[-10, Length[m]]〚i〛,
{i, 1, Length[m]}]
That works just fine.
Now I want to write a function f1
that performs this manipulation, and this is where I got stuck:
f1[q_] := Table[
q[[i, i]] = RandomInteger[{-10, 0}, Length[q]]〚i〛,
{i, 1, Length[q]}]
f1[m]
gives
Set::setps: {{20,24,33,36,34},{39,13,15,30,30},{18,17,16,28,27},{39,35,33,32,37},{30,21,22,10,23}} in the part assignment is not a symbol.
Set::setps: {{20,24,33,36,34},{39,13,15,30,30},{18,17,16,28,27},{39,35,33,32,37},{30,21,22,10,23}} in the part assignment is not a symbol.
Set::setps: {{20,24,33,36,34},{39,13,15,30,30},{18,17,16,28,27},{39,35,33,32,37},{30,21,22,10,23}} in the part assignment is not a symbol.
General::stop: Further output of Set::setps will be suppressed during this calculation.
Why is that?