Fit data with a curve in MATLAB

In summary, the speakers discuss the topic of fitting [x,y] data pairs with a mathematical function and the challenges of extrapolating from the data. They suggest using the method of divided differences or a non-linear least-square regression with weighted data. However, they also point out the importance of constraining the model and give an example of using a polynomial of order 18. They also suggest plotting the data on logarithmic coordinates for further insights.
  • #1
quin
50
0
Hi friends.
I want to fit my x datas and y datas with a function in the most exact way.my data is:

Code:
x=[0.3 0.5 0.7 0.9 1 1.3 1.4 1.5 2  3 5 7 9 10 30 50 70 90 100];
y=[13.4347 8.3372 6.3107 5.27 4.93 4.28 4.14 4.0199 3.6349 3.3178 3.1282 3.0691 3.0432 3.0354 3.0043 3.0016 3.0008 3.0005 3.0004];
and I ploted y vs x

can you give me the most suitable formula for the curve of these data?

thank you so much
 
Physics news on Phys.org
  • #2
It is possible to EXACTLY fit any finite number of [x,y] data pairs using the method of divided differences. N data points can be fitted exactly by a polynomial of degree N-1.
If you want something else out of the data, such as the ability to interpolate or parameters that have an actual meaning according to some model, then you will have to construct a mathematical model from a priori principles.
Your best bet then would be to use a non-linear least-square regression (weighted, if you can weigh the data) that will find the best fit of the data to the mathematical model. I recommend the Simplex method as being very robust and not too dependent on the initial estimates of the parameters (coefficients, constants, etc) in the model.
In the long run, the method you choose should be driven by what you already know about the source of the data, and by what you expect to get out of the data.
One caveat I feel must be made: don't expect extrapolations to mean much. Extrapolations are toys by which engineers, economists, and other non-scientists delude themselves.
 
  • #3
you are right but I just want to predict a few next points for taking them as my initial numbers for my program

so is there anybody who knows a way in MATLAB for finding the formula of plot of my points?
 
  • #4
The problem is you haven't given any constraints for your function. There are an infinite number of functions which fit your data exactly. You need to constrain the model by saying, for example, it should be a polynomial of order 18 (as tadchem suggested). This continuous model would at least make any extrapolation attempt somewhat dependant on the data.

MATLAB can solve the problem (in many different ways) once you do this. Until you do this, the problem is hugely ill-posed.
 
  • #5
MikeyW said:
The problem is you haven't given any constraints for your function. There are an infinite number of functions which fit your data exactly. You need to constrain the model by saying, for example, it should be a polynomial of order 18 (as tadchem suggested). This continuous model would at least make any extrapolation attempt somewhat dependant on the data.

MATLAB can solve the problem (in many different ways) once you do this. Until you do this, the problem is hugely ill-posed.

you are right but I tested a polynomial of order -6 to 6 . But it won't predict the continuation of my real function in a good way!
So what formula do you suggest for fitthing these datas?

thank you so much
 
  • #6
Just for starters, try plotting your [x,y] pairs on logarithmic coordinates. That may at least give you a hint of what the function may look like.
 

What is curve fitting in MATLAB?

Curve fitting in MATLAB involves finding a mathematical function that best represents a set of data points. This involves selecting a function and adjusting its parameters to minimize the difference between the predicted values and the actual data points.

What are the steps involved in fitting data with a curve in MATLAB?

The steps for fitting data with a curve in MATLAB are:

  • Import the data into MATLAB
  • Select a function that best describes the relationship between the data points
  • Define the function and its parameters
  • Use the curve fitting tool or the fit function to obtain the best-fit parameters
  • Plot the fitted curve with the data points to visualize the fit

How do I choose the appropriate function for curve fitting in MATLAB?

Choosing the appropriate function for curve fitting depends on the type of relationship between the data points. Some common functions used for curve fitting include linear, exponential, logarithmic, and polynomial functions. It is important to select a function that accurately represents the data and has a reasonable number of parameters.

What is the difference between linear and nonlinear curve fitting in MATLAB?

Linear curve fitting involves fitting data with a linear function, such as a straight line. Nonlinear curve fitting, on the other hand, involves fitting data with a nonlinear function, which can take various forms such as exponential, logarithmic, or polynomial functions. Nonlinear curve fitting can capture more complex relationships between the data points, but it may also result in overfitting if not done carefully.

How can I assess the goodness of fit for a curve in MATLAB?

There are several ways to assess the goodness of fit for a curve in MATLAB. One common method is to calculate the coefficient of determination, R^2, which measures the proportion of the variation in the data that is explained by the fitted curve. Another method is to visually inspect the plot of the fitted curve with the data points to see how closely they match. Additionally, you can also perform statistical tests, such as the chi-square test, to evaluate the significance of the fit.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • Calculus
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
8K
Back
Top