3
$\begingroup$

I have created this code and was wondering if you could suggest a less convoluted way of solving the problem. I have two lists:

unitvector={{0.662689, 0.748895}, {0.715053, 0.69907}, {0.763178, 
  0.646188}, {0.821767, 0.569823}, {0.85637, 0.516362}, {0.891767, 
  0.452495}, {0.926008, 0.377505}, {0.93515, 0.354251}, {0.930926, 
  0.365209}, {0.947215, 0.320599}, {0.943255, 0.33207}, {0.866993, 
  0.49832}, {0.497458, 0.867488}, {0.396184, 0.918171}, {0.374449, 
  0.927248}, {0.118057, 0.993007}, {0.0974299, 0.995242}, {0.0334211, 
  0.999441}};


incl={{0.26706}, {0.247503}, {0.232131}, {0.215581}, {0.193663}, 
    {0.185976}, {0.161986}, {0.155111}, {0.136908}, {0.118314},
    {0.106016}, {0.100337}, {0.100511}, {0.108912}, {0.115234},
    {0.151056}, {0.183037}, {0.200112}};

I want to multiply every element in unitvector by the relative value in inlc, which is timed each time by an incremental number from 0 to 20. My code is as follows:

a = Flatten[
   Transpose[Table[unitvector[[1 ;;, 1]]*(i*incl), {i, 0, ndiv}]]];
b = Flatten[
   Transpose[Table[unitvector[[1 ;;, 2]]*(i*incl), {i, 0, ndiv}]]];
points = Partition[Partition[Riffle[a, b], 2], Length[unitvector]];

Then plotting the results should look like this:

enter image description here

$\endgroup$
6
$\begingroup$

A fair bit simpler than what you are doing:

ndiv = 20;

foo = unitvector * Flatten[incl];
bar = Table[i*foo, {i, 0, ndiv}] ~Flatten~ {2, 1};
points2 = Partition[bar, Length @ foo];

points == points2   (* True *)
|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ "A fair bit simpler than what you are doing", with "laddie" tacked on, read in the voice of Scotty... +1 $\endgroup$ – ciao Jun 16 '16 at 11:29
  • $\begingroup$ @ciao LOL I can hear that now :-) $\endgroup$ – Mr.Wizard Jun 16 '16 at 11:30
  • $\begingroup$ @ciao. Surely Scotty would say "A muckle simpler than what ye be doing, Cap'n" $\endgroup$ – m_goldberg Jun 16 '16 at 12:57
3
$\begingroup$
data = Table[
   Table[
     unitvector[[i]] Flatten[incl][[i]] j, {i, 1, Length[incl]}], {j, 0, 20}];
ListPlot[data]

enter image description here

Or, if you want, Transpose the data, for data=Transpose[data]

enter image description here

|improve this answer|||||
$\endgroup$
  • $\begingroup$ @Kuba Indeed, edited. $\endgroup$ – Feyre Jun 16 '16 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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