I want to take two lists of the same length: widths and weights, and sum a function (of 3 variables) over a single index using the elements from both lists that have that index. Then I want to plot the function.
If I only sum over one of the lists, I can use
scatterfunc[x1_, x2_, y1_] =
Sum[y1/(4*x1) + (1 - y1)/(4*x2) -
y1/(gamma + x1) - (1 - y1)/(gamma + x2), {gamma, widths}];
Manipulate[
ContourPlot[scatterfunc[x1, x2, y1], {x1, 0, 1}, {x2, 0, 1},
ColorFunction -> "GrayTones", PlotLegends -> Automatic], {y1, 0, 1}]
But I've been unable to find the equivalent of python's zip(widths,weights) in order to sum over a single index using both lists. I want something like
scatterfunc[x1_, x2_, y1_] =
Sum[y1/(4*x1) + (1 - y1)/(4*x2) -
alpha*y1/(gamma + x1) - (1 - y1)/(gamma + x2), {{gamma,alpha}, zip[widths,weights]}];
Manipulate[
ContourPlot[scatterfunc[x1, x2, y1], {x1, 0, 1}, {x2, 0, 1},
ColorFunction -> "GrayTones", PlotLegends -> Automatic], {y1, 0, 1}]
Thanks.
zip()is effectively the same asTranspose[], but your problem looks as if it will be better served byMapThread[]+Total[]. – J. M.'s missing motivation Jul 29 '15 at 16:46Sum[...ww[[1]]...ww[[2]],{ww,Transpose@{widths,weights}} ]. Whereww[[1]]is width, andww[[2]]is weight. – N.J.Evans Jul 29 '15 at 16:47Sumat all becausePlusandTimesautomatically thread over lists. Start by reading http://reference.wolfram.com/language/howto/CombineAndRearrangeLists.html – Jens Jul 29 '15 at 16:49f @ xis just the same asf[x]; a prefix form of function application to a single argument. – J. M.'s missing motivation Jul 29 '15 at 17:06