2
$\begingroup$

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

$\endgroup$
4
  • 2
    $\begingroup$ 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 $\endgroup$
    – Kuba
    Sep 24, 2018 at 11:14
  • $\begingroup$ If all else fails, you could consider using ReplacePart[]... $\endgroup$ Sep 24, 2018 at 11:21
  • $\begingroup$ After some inspection, we can clearly see that the toy code is only concerned with the very first sublist of elettrone. $\endgroup$
    – LLlAMnYP
    Sep 24, 2018 at 11:59
  • $\begingroup$ By the way, I do not get n in version 10.2, I get 1, 2, and 3. $\endgroup$
    – LLlAMnYP
    Sep 24, 2018 at 12:13

1 Answer 1

1
$\begingroup$

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
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.