1
$\begingroup$

SOLVED: Thanks to Daniel below, I should index as expected as [[All,All,1] for er etc. My mistake came as I was trying to index from 0, which Mathematica does not like!

I've spent a while reading other posts on this so hopefully it's not a duplicate as I couldn't find the answer.

I have a function which calculates 3 vector components of the electric field {er,e$\phi$,ez} at a particular point in 2D space, and wish to calculate that over a plane {r,$\phi$}. My function returns {er,e$\phi$,ez} for a given pair of inputs, and the results are put into a ParallelTable

EFieldIn[r_, \[Phi]_, ....]:=Module[{.....},  
    ... ;
    Return[{er, ep, ez}];
];

Ein = ParallelTable[EFieldIn[r, \[Phi], ......, {r, 175 10^-9, 500 10^-9,dr}, {\[Phi], -\[Pi], \[Pi], dp}];

I've omitted the other arguments and sections of code for clarity as they're not relevant.

This produces a table {{{er,ep,ez},{er2,ep2,ez2},......,{erN,epN,ezN}}}

My question is about how to index this to get the three NxN arrays of er e$\phi$ and ez independently? Everything I have tried so far using what I know of normal indexing of a 1 and 2D list has not been working.

$\endgroup$
6
  • $\begingroup$ Ein[[All,1]] gives er. Ein[[All,2]] gives ep. Ein[[All,3]] gives ez. $\endgroup$ Commented Jan 12, 2022 at 8:52
  • $\begingroup$ Welcome to the community. If I get it right, you have a list consisting of lists of tuples ({er,ep,ez}). First use Catenate to get a list of tuples, then apply Transpose to give you three lists with the length of N. $\endgroup$
    – Ben Izd
    Commented Jan 12, 2022 at 8:53
  • $\begingroup$ @DanielHuber Thanks. I have tried this and it just returns a 1D List = {List,List,List,List,.........,List} which any further parts of my code refuse to treat as a suitable result. I have tried to index further and it just returns "List" or "Symbol" that cannot be used in any mathematical sense. $\endgroup$
    – D. Brown
    Commented Jan 12, 2022 at 9:03
  • $\begingroup$ @BenIzd Thanks, this is close, although they should be lists of NxN in the end. I will see what I can do further with this type of method though $\endgroup$
    – D. Brown
    Commented Jan 12, 2022 at 9:04
  • $\begingroup$ @DanielHuber It appears my python knowledge bled over into my Mathematica inexperience as I was trying to index at [[All,0]] so it didn't work. Thanks, this seems to work mostly if I index with a third element eg. [[All,1,2]]. I just need to figure out what each is. $\endgroup$
    – D. Brown
    Commented Jan 12, 2022 at 9:11

0

Browse other questions tagged or ask your own question.