2
$\begingroup$

I have the following:

first= {1+a,2+a,3+a,4+a}

and a list

t={0,1,2,3}

I want to evaluate the first element of "first" at the first element of "t" (plug in "a" the first element of "t"), then the second element of "first" evaluated at the second element of "t" and so on. Finally, I want to plot the result in the y axis against the list "t" in the x axis. How can I do this? I have tried using Table, Do, and Function Map but I cant figure out how to do this.

$\endgroup$
3
$\begingroup$
first = {1 + a, 2 + a, 3 + a, 4 + a};
t = {0, 1, 2, 3};
MapThread[#1 /. a -> #2 &, {first, t}]
(* {1, 3, 5, 7}*)

or

#[[1]] /. a -> #[[2]] & /@ Transpose@{first, t}
(* {1, 3, 5, 7}*)
$\endgroup$
0
$\begingroup$
result = ReplacePart[first, Thread[Rule[Position[first, a], t]]]
ListPlot[Transpose[{t, result}]]
$\endgroup$

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.