# Understanding this Set error

Given the toy vector:

elettrone={{1.5, 1.5, 0.064, 1.4289, -2.0901, 790.138},{1.5, 1.5, 0.064, 1.4289, -2.0901, 790.138},{1.5, 1.5, 0.064, 1.4289, -2.0901, 790.138}}


I try to change the first three elements as follows:

elettrone[[All, 1]][[1]] -=
dx*Sin[elettrone[[All, 4]][[1]]]*Cos[elettrone[[All, 5]][[1]]];
elettrone[[All, 2]][[1]] -=
dx*Sin[elettrone[[All, 4]][[1]]]*Sin[elettrone[[All, 5]][[1]]];
elettrone[[All, 3]][[1]] -= dx*Cos[elettrone[[All, 4]][[1]]];


with dx=0.0001. I get the error:

Set::partd: Part specification elettrone[[All,1,n]] is longer than depth of object.

Set::partd: Part specification elettrone[[All,2,n]] is longer than depth of object.

Set::partd: Part specification elettrone[[All,3,n]] is longer than depth of object.

How can this error appear I am not writing elettrone[[All,1,n]]!

I am using version 11.3 for windows

• Not sure the exact source but it is probably related to the fact that you can't do a[[All, 1]][[2]] = ... you need to do a[[2, 1]] = .... See: Part not behaving the way I expect it to – Kuba Sep 24 '18 at 11:14
• If all else fails, you could consider using ReplacePart[]... – J. M. is in limbo Sep 24 '18 at 11:21
• After some inspection, we can clearly see that the toy code is only concerned with the very first sublist of elettrone. – LLlAMnYP Sep 24 '18 at 11:59
• By the way, I do not get n in version 10.2, I get 1, 2, and 3. – LLlAMnYP Sep 24 '18 at 12:13

The same thing that your code seems to want to do can be done by the following:

With[{dx = 0.0001},
MapAt[
{#1 - dx Sin[#4] Cos[#5], #2 - dx Sin[#4] Sin[#5], #3 - dx Cos[#4], #4, #5} & @@ # &,
elettrone, {1}
]
]


or, to extend the same pattern to every sublist

{#1 - dx Sin[#4] Cos[#5], #2 - dx Sin[#4] Sin[#5], #3 - dx Cos[#4], #4, #5} & @@@ elettrone