Multiplying two data sets which don't have the same length or spacing

In summary, ademus is trying to multiply two data sets, but the lengths are different, the data has non-uniform energies, and he is using interpolation to get the data to work.
  • #1
ademus4
2
0
As the post title describes, I have two data sets and want to multiply them together (and finally plot them). The problem I have is that the data are different length, so for example using Matlab:

>>> data_set1 .* data_set2

But this would not give me the correct answer for a number of reasons.

The data share the same x-axis (energy in MeV). The trouble is the first data starts around 0 MeV and ends around 11. The second data starts just before the end of the first data and extends further on. The region in which they overlap is the part I am interested. Another issue I have is the length between data points is non-uniform in both data sets.

Is there a process to normalise or do something with the data to make them 'compatible'?

For tools, I am using anything I can get my hands on. Excel for basic ideas, Python (Numpy and MatplotLib) for proper data analysis. I am fairly comfortable with Matlab but I don't have it where I work now (I can however download Octave).
 
Technology news on Phys.org
  • #2
If you're only interested in the overlap region, start by throwing away everything else. Keep only the points in the first data set which are higher energy than the minimum energy of the second data set, and similarly keep only the points in the second data set which are less than the maximum energy of the first.

You say that the length between the data points is non-uniform, but don't specify if the specific energies are the same in each data set, or different. If they're the same, then you're done once you take the overlap. If they're different, then you'll have to interpolate at least one of the data sets. You can interpolate one of the data sets onto the points where the other is evaluated, or interpolate them both onto some other set of points. If you need to work with them in future calculations, it might simplify things to interpolate them both onto a uniformly spaced set of points.
 
  • #3
Hi ademus, is your data smooth enough to be reasonably interpolated?

If so try the MATLAB cubic spline. It is easy to use: y_new = spline(x, y, xnew), where "x" and "y" are your original data and "xnew" is the set of x samples points that you would like to use and "ynew" is the corresponding interpolated y data.
 
  • #4
yeah, what uart said.

if you don't have matlab, you can do the same thing with python with scipy.interpolate, see this on-line example, for instance.
 
  • #5
Thanks for the responses!

In the end I used the 'interpolate' function from Scipy in Python, which worked perfectly!

Here is of plot of the data (without labels etc, the blue and green data are multiplied to make the red data):

no_labels.png
 

1. How do you multiply two data sets with different lengths and spacing?

Multiplying two data sets with different lengths and spacing requires first aligning the data sets to a common interval. This can be done through interpolation or extrapolation, depending on the nature of the data. Once the data sets are aligned, they can be multiplied using standard multiplication techniques.

2. What is the purpose of multiplying two data sets with different lengths and spacing?

Multiplying two data sets with different lengths and spacing can be useful for analyzing correlations and relationships between the two sets of data. It can also be used to generate a new data set that combines information from both original sets.

3. Can data sets with different units be multiplied?

Yes, data sets with different units can be multiplied. However, it is important to ensure that the resulting units make sense and are properly labeled.

4. How do you handle missing data points when multiplying two data sets?

If there are missing data points in one or both data sets, they can be interpolated or extrapolated to fill in the gaps before multiplying. However, it is important to consider the potential impact of these estimations on the accuracy of the results.

5. Are there any limitations to multiplying two data sets with different lengths and spacing?

Yes, there are some limitations to multiplying two data sets with different lengths and spacing. These include potential errors from interpolation or extrapolation, as well as the assumption that the data sets are truly related and can be accurately multiplied.

Similar threads

  • Programming and Computer Science
Replies
14
Views
622
  • Programming and Computer Science
Replies
11
Views
991
  • Programming and Computer Science
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
976
  • STEM Educators and Teaching
Replies
5
Views
645
  • Programming and Computer Science
Replies
1
Views
624
  • Set Theory, Logic, Probability, Statistics
Replies
4
Views
904
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • General Math
Replies
6
Views
782
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top