Re: Adding two Plots in Mathematica?
- From: Jean-Marc Gulliet <jeanmarc.gulliet@xxxxxxxxx>
- Date: Tue, 23 Oct 2007 23:05:59 +0200
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
.
- References:
- Adding two Plots in Mathematica?
- From: Tim
- Adding two Plots in Mathematica?
- Prev by Date: Re: Adding two Plots in Mathematica?
- Next by Date: [Mathematica] How can I speed up drawing of 2D graphs?
- Previous by thread: Re: Adding two Plots in Mathematica?
- Next by thread: differential Equation Problem
- Index(es):
Relevant Pages
|
|