2

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.

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

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

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

I am using version 11.3 for windows

mattiav27
  • 6,677
  • 3
  • 28
  • 64

1 Answers1

1

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
LLlAMnYP
  • 11,486
  • 26
  • 65