Finding an oscillator's period with a dataset in Mathematica

In summary, the conversation is about a person trying to find the period of an oscillator using the NonLinearRegress function in Mathematica. They have a dataset of 51 measurements and are encountering an error when trying to use the code provided. They have also provided a link to the dataset for reference.
  • #1
Shukie
95
0

Homework Statement


I have a dataset of an oscillator with 51 measurements, I uploaded it http://home.orange.nl/~kuip3148/osc.dat . It's in the form of {time, position}. I have to find the period of this oscillator in Mathematica.

Homework Equations


I have to use the NonLinearRegress function to find it.


The Attempt at a Solution


I started with the following code:
Code:
data = {oscdata};
{tdata, xdata} = Transpose[data]

Homework Statement


That gives me the first problem, because I get an error saying the two lists are not the same shape, while they clearly are. Anyone know why that's happening?

Code:
"Lists {tdata,xdata} and \
{{{0,0.369}},{{0.1,0.0999}},{{0.2,0.0904}},{{0.3,-0.054}},{{0.4,-0.1}}\
,{{0.5,-<<6>>}},{{0.6,-0.328}},{{0.7,-0.388}},{{0.8,-0.486}},{{0.9,-0.\
576}},<<51>>} are not the same shape"
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
That's strange, it worked perfectly here

Code:
data = Import["[PLAIN]http://home.orange.nl/~kuip3148/osc.dat"][/PLAIN] 
{tdata, xdata} = Transpose[data]
 
Last edited by a moderator:
  • #3


As a scientist, your first step would be to troubleshoot and identify the source of the error. In this case, it seems like the issue could be with the formatting of the dataset. It is possible that there are extra characters or formatting errors that are causing the lists to be of different shapes.

To address this, you can try using the Import function in Mathematica to directly import the data from the provided link. This may help to eliminate any potential formatting errors.

Once the dataset is properly imported, you can use the NonlinearRegress function to fit a nonlinear model to the data and determine the period of the oscillator. This function allows you to specify the model, in this case, a sinusoidal function, and it will provide the best fit parameters, including the period.

Overall, it is important to carefully check the formatting and structure of the data before attempting to analyze it in Mathematica. Troubleshooting errors and ensuring the data is clean and properly formatted will lead to more accurate and reliable results.
 

FAQ: Finding an oscillator's period with a dataset in Mathematica

How do I import my dataset into Mathematica?

To import a dataset into Mathematica, you can use the "Import" function. This function allows you to specify the file path or URL of your dataset and choose the appropriate format. For example, if your dataset is in a CSV format, you can use the command "Import["data.csv", "CSV"]" to import it into Mathematica.

How can I plot my dataset in Mathematica?

To plot your dataset in Mathematica, you can use the "ListPlot" function. This function takes in a list of data points and creates a graphical representation of the data. You can customize the plot by specifying the axes labels, title, and other options.

What is an oscillator's period?

An oscillator's period refers to the time it takes for one complete cycle of oscillation. In other words, it is the time it takes for the oscillating object to return to its starting position. In the context of a dataset, it can also refer to the time it takes for a repeating pattern to occur.

How can I use Mathematica to find an oscillator's period from a dataset?

To find an oscillator's period from a dataset in Mathematica, you can use the "Periodogram" function. This function calculates the frequency components of a dataset and identifies the dominant frequencies. The period of the oscillator can then be determined from the dominant frequency.

Can I use Mathematica to fit a curve to my dataset and find the oscillator's period?

Yes, you can use the "FindFit" function in Mathematica to fit a curve to your dataset and determine the period of the oscillator. This function allows you to specify the type of curve to fit and the parameters to optimize. You can then extract the period from the fitted curve.

Back
Top