I am creating some simple graphs of functions defined by ordered pairs. Students are learning about "operations on functions", in this case, adding functions.
If I have two functions defined by ordered pairs, how do I add them? I know this must be a simple list processing thing, I would appreciate any help.
I.E.
functiong = {{-5, -5}, {-3, -3}, {1, 1}, {2, 2}, {5, 5}};
functionf = {{-5, 4}, {-3, 2}, {1, 2}, {2, 5}, {5, 5}};
I want to have the sum....
sum = {{-5, -1}, {-3, -1}, {1, 3}, {2, 7}, {5, 10}};
Easy to do manually, but if I modify the lists to create new examples, I'd like to have Mathematica "add" those lists for me....
Edit
Below, an example of the kind of question I see in the textbooks the students are using. They are told that what they see is function $f$ (red) and function $g$ (blue) and asked to draw $(f+g)(x)$
My question is answered, but now that the context is clear, I would of course welcome any further suggestions on ways to easily create similar (and perhaps more interesting , but not harder!) problems.
Answer
One way :
MapThread[{#1[[1]], #1[[2]] + #2[[2]]} &, {functiong, functionf}]
(* {{-5, -1}, {-3, -1}, {1, 3}, {2, 7}, {5, 10}} *)
Comments
Post a Comment