6
$\begingroup$

I have a list of scalar functions of two variables. Say, it is:

list1 = {Sin[x]*Cos[y], Exp[x] - Log[y] + x^2, sin[x], Sin[x]/Sec[y]}

I have another list containing the inputs to each scalar function in the list:

list2 = {{0.5,0.6},{0.6,0.7},{0.7,0.8},{0.8,0.9}}

How do I evaluate each function in list1 at the values x and y corresponding to the relevant position in list2

$\endgroup$

2 Answers 2

6
$\begingroup$
MapThread[Function[{x, y}, #] @@ #2 &, {list1, list2}]
{0.395687, 2.53879, sin[0.7], 0.445916}

Old misunderstood:

list1 /. Thread[{x, y} -> #] & /@ list2

{
 {0.395687, 2.40955, sin[0.5], 0.395687}, 
 {0.431862, 2.53879, sin[0.6], 0.431862}, 
 {0.448831, 2.7269, sin[0.7], 0.448831}, 
 {0.445916, 2.9709, sin[0.8], 0.445916}
}
$\endgroup$
4
  • $\begingroup$ Shouldn't I be getting a list where each entry is a single real number? Implicitly, I have assumed that the first entry in list2 corresponds to x and the second entry in list2 corresponds to y. $\endgroup$ Sep 8, 2016 at 8:24
  • 1
    $\begingroup$ As I understand it the OP only wants the diagonal of your result... $\endgroup$
    – sebhofer
    Sep 8, 2016 at 8:28
  • $\begingroup$ What I want is that the first "function" in list 1 is evaluate at the first entry in list 2, the second "function" in list 1 is evaluate at the second entry in list 2 and so on. $\endgroup$ Sep 8, 2016 at 8:28
  • $\begingroup$ @sebhofer thanks, fixed. $\endgroup$
    – Kuba
    Sep 8, 2016 at 8:30
2
$\begingroup$

another version

list1 /. {x -> #1, y -> #2} & @@@ list2

{{0.395687, 2.40955, sin[0.5], 0.395687},
 {0.431862, 2.53879, sin[0.6], 0.431862},
 {0.448831, 2.7269, sin[0.7],  0.448831},
 {0.445916, 2.9709, sin[0.8], 0.445916}}
$\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.