Fitting Curve to Data Points using Mathematica

In summary, the conversation discusses using Mathematica to fit a curve to a set of data points. The speaker mentions using the Fit option and trying other methods, but ultimately prefers using Excel. They explain their process for performing a least-squares fit using any function in Excel.
  • #1
Dustinsfl
2,281
5
I am trying to use Mathematica to fit a curve to these data points
Code:
ListPlot[{{2*Pi/(1 - 0^2/16), 5 (3 - Log[2])}, {2*Pi/(1 - .05^2/16), 
   10 (3 - Log[2])}, {2*Pi/(1 - .1^2/16), 
   15 (3 - Log[2])}, {2*Pi/(1 - .15^2/16), 
   20 (3 - Log[2])}, {2*Pi/(1 - .2^2/16), 
   25 (3 - Log[2])}, {2*Pi/(1 - .25^2/16), 
   30 (3 - Log[2])}, {2*Pi/(1 - .3^2/16), 
   35 (3 - Log[2])}, {2*Pi/(1 - .35^2/16), 
   40 (3 - Log[2])}, {2*Pi/(1 - .4^2/16), 
   45 (3 - Log[2])}, {2*Pi/(1 - .45^2/16), 50 (3 - Log[2])},}, 
 PlotRange -> {{6.28, 6.39}, {10, 116}}]
However, I tried the Fit option and some other put it doesn't seem to work.
 
Physics news on Phys.org
  • #2
I typically go with Excel as follows:

1. Put actual data in one column.

2. Use a few cells to write in the changeable arbitrary parameters of the function you want to fit.

3. Write the column next to the first one as having your theoretical curve, making sure to use $F$5 (for example), for the cells in step 2.

4. In the next column over, set cells equal to =(B2-A2)*(B2-A2).

5. Sum this last column.

6. Use the Solver routine to minimize the sum cell in step 5 subject to changing the parameters in step 2.

This is least-squares fit using any function you can write in Excel, which is quite a few.
 

FAQ: Fitting Curve to Data Points using Mathematica

How do I import my data into Mathematica?

To import your data into Mathematica, you can use the Import function. This function allows you to specify the file format and location of your data. You can also use the Import function to import data from online sources or from a database.

How do I plot my data points in Mathematica?

To plot your data points in Mathematica, you can use the ListPlot function. This function takes in a list of data points and plots them on a graph. You can also customize the appearance of your plot by specifying options such as color, markers, and labels.

What is the best method for fitting a curve to my data points?

The best method for fitting a curve to your data points depends on the type of data and the shape of the curve you are trying to fit. Some common methods include linear regression, polynomial regression, and nonlinear curve fitting. Mathematica offers a variety of built-in functions for these methods, such as Fit, FindFit, and NonlinearModelFit.

Can I add error bars to my data points when fitting a curve?

Yes, you can add error bars to your data points when fitting a curve in Mathematica. This can be done by using the ErrorBar option in the ListPlot function or by using the ErrorBarFunction option in the Fit or FindFit functions. You will need to provide the error values for each data point in order for the error bars to be displayed.

How do I determine the accuracy of my fitted curve?

Mathematica provides various measures of accuracy for your fitted curve, such as residuals, root-mean-square error, and coefficient of determination. These can be obtained by using the functions Residuals, RootMeanSquareError, and CoefficientOfDetermination, respectively. You can also visualize the accuracy of your fitted curve by plotting the residuals or by comparing it to the original data points.

Similar threads

Replies
10
Views
1K
Replies
1
Views
1K
Replies
4
Views
2K
Replies
4
Views
1K
Replies
10
Views
2K
Replies
6
Views
3K
Replies
1
Views
1K
Replies
6
Views
2K
Replies
12
Views
5K
Back
Top