0
$\begingroup$

Let's say I have two lists $L_1=\{a_1,...,a_5\}$ and $L_2=\{b_1,...,b_10\}$. Is there an easy way to make new lists from convex combinations of these two lists' entries? Let me be more specific:

1 Suppose the two lists $L_1,L_2$ are of equal length $n$; how do I create a new list whose entries are linear combinations of the entries in $L_1,L_2$? I first defined $f(x)=wx$ and $g(x)=(1-w)x$ and then used Map[(# + Map[f, list1]) &, {Map[g, list2]}]. This works but it's not very neat, is there another way? (Let's call such a hypothetical neat function $u$.)

2 Now let's go back to the lists of unequal length. I wanna be able to apply $u$ to sublists of $L_1$ and $L_2$ of length at most five. One could of course delete entries from the lists in question and then apply $u$, but I'm thinking there's gotta be a better way, but how? That is to say, how do I make a function where I can specify to map the first two entries of each list to a 2-list (producing the list $\{wa_1+(1-w)b_1,wa_2+(1-w)b_2\}$), or to map the second and third entries of each list to a 2-list? (producing the list $\{wa_2+(1-w)b_2,wa_3+(1-w)b_3\}$). On this one I'm completely lost.

Thanks in advance :)

EDIT: With h[x_,y_]:=wx+(1-w)y, Apply[h,{list1,list2}] answers question 1.

$\endgroup$
2
  • 2
    $\begingroup$ (1) Please use code tags as appropriate. (2) I don't follow your notation. Would you please give an example of the actual input and output that you desire? $\endgroup$
    – Mr.Wizard
    Commented Feb 9, 2015 at 11:28
  • $\begingroup$ Input are two lists of different length, output as in the example in question 2. $\endgroup$ Commented Feb 9, 2015 at 11:32

2 Answers 2

2
$\begingroup$

Perhaps (for equal length lists)

foo[h_, l1_, l2_, parts_] := h@@@Transpose[{l1, l2}][[parts]]
(* or foo[h_, l1_, l2_, parts_] := Apply[h, Transpose[{l1, l2}][[parts]], 1] *)

{l1, l2} = Array[#, {5}] & /@ {a, b};
h[x_, y_] := w x + (1 - w) y

foo[h, l1, l2, {2, 3}]
(* {w a[2] + (1 - w) b[2], w a[3] + (1 - w) b[3]} *)

?

$\endgroup$
1
  • $\begingroup$ Thanks! Not sure what's going on there though, and the output is wrong, although I'm sure it can be fixed quite easily... I'll look into it more later :) $\endgroup$ Commented Feb 9, 2015 at 11:50
1
$\begingroup$

If the length of list1 and list2 are the same, I think you can form the convex hull of the pointset formed by transposing them - since every point in a convex hull is a convex combination of some of these points.

list1 = RandomVariate[NormalDistribution[], 50];
list2 = RandomVariate[NormalDistribution[], 50];
pts = Transpose[{list1, list2}];
reg = ConvexHullMesh[pts]

You may now test any point {x,y} for membership in this convex hull by doing

{x,y}\[Element]reg

The coordinates in the convex hull are those that are convex combinations of list1 and list2 simultaneously. I assume this is what you really want. If you wanted any convex combination in either list1 or list2, this would just be a boring rectangle of dimensions {{Min[list1],Max[list1]},{Min[list2],Max[list2]}}

You can now generate random numbers, form pairs of them {a,b} and test for membership in the region. Then randomly choose a or b and put that in a list, rinse repeat, you have a convex combination list.

$\endgroup$

Your Answer

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

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