Re: Adding two Plots in Mathematica?



Tim wrote:

I have two lists A and B in Mathematica.
Both of them lists a set of pairs.

A is of the structure (x1, y1), ..., (x10, y10)
and B is of the structure (x1, z1), ..., (x1, z10).

I can easily plot A resp. B by typing
ListPlot[A] resp. ListPlot[B].

Now, I would like to add both plots.
I set
C = A + B

But ListPlot[C] is then giving me a plot of the points
(x1 + x1, y1 + z1), ..., (x10 + x10, y10 + z10)
where I am only interested in the plot of the points
(x1, y1 + z1), ..., (x10, y10 + z10).

In other words: How can I just add the second coordinates
of the lists A and B while keeping the first coordinates?

One possible way is the following (see In[3]):

In[1]:= lst1 = Table[{x, RandomInteger[{0, 10}]}, {x, 1, 10}]
lst2 = Table[{x, RandomInteger[{0, 10}]}, {x, 1, 10}]

Out[1]= {{1, 5}, {2, 9}, {3, 9}, {4, 3}, {5, 4}, {6, 4}, {7, 9}, {8,
7}, {9, 3}, {10, 0}}

Out[2]= {{1, 2}, {2, 7}, {3, 7}, {4, 1}, {5, 10}, {6, 0}, {7, 10}, {8,
6}, {9, 6}, {10, 9}}

In[3]:= lst3 =
Transpose[{lst1[[All, 1]], lst1[[All, 2]] + lst2[[All, 2]]}]

Out[3]= {{1, 7}, {2, 16}, {3, 16}, {4, 4}, {5, 14}, {6, 4}, {7,
19}, {8, 13}, {9, 9}, {10, 9}}

(Note that in general it is not a good idea to use capital letters for variable names because some Mathematica reserved symbols for operators or functions are single capital letter such as D for the differential operator, E for the exponential function, C for constant of integration, etc.)

Regards,
--
Jean-Marc
.



Relevant Pages

  • Re: a little observation on Maple and Mathematica and support of functions that acts on lists/sequen
    ... functions) and many functions that automatically handle lists, ... eg Plot is not "Listable", Plot of a list of functions ... {Abs, AiryAi, AiryAiPrime, AiryBi, AiryBiPrime, Apart, ArcCos, ...
    (sci.math.symbolic)
  • Re: plotting in R
    ... Marc Schwartz schrieb: ... under the Mailing Lists link. ... plot.formula(), which is a plot method that will be dispatched if the ... the 'data' argument must be a data frame. ...
    (sci.stat.math)
  • Re: plotting in R
    ... R specific programming queries are best posted to the r-help ... under the Mailing Lists link. ... plot.formula(), which is a plot method that will be dispatched if the ... the 'data' argument must be a data frame. ...
    (sci.stat.math)
  • Mathematica problem - generate filename automatically
    ... I have a load of text files for which I'd like to plot the data in them. ... But how can I best combine those lists, so it creates a file name? ... I'm tempted to write a C program to generate the Mathematica commands, but I'm sure it must be possible to do this in Mathematica - I just know C better! ...
    (sci.math.symbolic)
  • plotting data in MuPAD
    ... I am trying to plot data sets in MuPAD, ... formatting lists so that MuPAD can plot them. ... My data files are time ...
    (sci.math.symbolic)