Equation of nonlinear data

Hello,
If I have data
rA = [-0.2 -0.0167 -0.00488 -0.00286 -0.00204];
X = [0 0.1 0.4 0.7 0.9];
and I plot
plot(X,-FA0./(rA/60))
xlabel('X')
ylabel('-FA0/rA')
title('FA0/-rA vs. Conversion')
How would I be able to find an equation that represents this non-linear plot? Thanks
I want rA as a function of X
perhaps it would be better visually to see plot(X,rA/60)
which is very nonlinear, but how would I represent this as an equation?

1 Comment

Looks almost perfectly linear to me (with a scalar ‘FA0’), but we’re missing ‘FA0’. Is it a scalar or vector?
Is there a specific process that generated these data that you want to estimate the parameters for? If so, what is it?

Sign in to comment.

 Accepted Answer

Stephen23
Stephen23 on 16 Sep 2014
You want to determine a function that matches your data. Doing this really depends on what you know about the data:
  • If you know the underlying function, then use this and fit it using least squares , or some tool from the curve fitting toolbox .
  • If you do not know the function, then model it using a spline or pchip function, using the polynomial output together with unmkpp .

17 Comments

Here is my output, how do I interpret this?? It gives multiple coefficient from unmkpp
pp = spline(X,rA/60)
pp =
form: 'pp'
breaks: [0 0.1000 0.4000 0.7000 0.9000]
coefs: [4x4 double]
pieces: 4
order: 4
dim: 1
EDU>> [breaks,coefs,l,k,d] = unmkpp(pp)
breaks =
0 0.1000 0.4000 0.7000 0.9000
coefs =
0.1429 -0.1462 0.0437 -0.0033
0.1429 -0.1033 0.0188 -0.0003
-0.0317 0.0253 -0.0046 -0.0001
-0.0317 -0.0033 0.0020 -0.0000
l =
4
k =
4
d =
1
I get the coefficients of the polynomial, but it gives 4 options
pp.coefs
ans =
0.1429 -0.1462 0.0437 -0.0033
0.1429 -0.1033 0.0188 -0.0003
-0.0317 0.0253 -0.0046 -0.0001
-0.0317 -0.0033 0.0020 -0.0000
And I tested all of them, for example
f = @(x) -.0003+0.0188*x-0.1033*x.^2+0.1429*x.^3
f =
@(x)-.0003+0.0188*x-0.1033*x.^2+0.1429*x.^3
x = linspace(0,1,100);
plot(x,f(x))
and none of these 4 options give a curve that resembles plot(X,rA/60)
Basically the output pp contains all of the information about the splines that fit your data, including the spline coefficients and boundaries (usually the x-data). There are some detailed explanations of this online:
Stephen23
Stephen23 on 16 Sep 2014
Edited: Stephen23 on 16 Sep 2014
I just realized in your case this may not be what you are looking for, as these functions are intended for interpolation and fit a different spline between each pair of X-data points, whereas you are looking for something more like a smoothing spline or a polynomial curve fit . With a polynomial fit you can exactly match any data with a order-n polynomial, but as the order gets higher, so does the tendency to create wildly oscillating functions.
So then how would I make a smoothing spline?
You have to purchase the curve fitting toolbox, right? I just have the student edition of matlab.
Stephen23
Stephen23 on 16 Sep 2014
Edited: Stephen23 on 16 Sep 2014
Smoothing splines can be achieved using the function csaps . For polynomial curve fitting, look at polyfit .
Though I repeat again: there is NO magic tool to solve your problem, it depends entirely on how the data behaves, what kind of system it describes, what you wish to do with the equations,...
Rick
Rick on 16 Sep 2014
Edited: Rick on 16 Sep 2014
The csaps function requires a function input, I believe. It won't let me put in the data for thei nputs (x,y) or I just get
pp = csaps(X,rA/60)
Undefined function 'csaps' for input arguments of type 'double'.
I did polyfit(X,rA/60,2) as well as 3, and I checked the outputs as anonymous functions, and the polynomial behavior is not really the same as plot(X,rA/60), which essentially asymptotes at 0 at around X=0.4
polyfit(X,rA/60,2)
ans =
-0.0081 0.0097 -0.0024
f
f =
@(x)-0.0024+0.0097*x-0.0081*x.^2
plot(x,f(x))
Well, I have an equation I am trying to solve
-0.41*X/400 = rA
And I know rA is a function of X, so I was trying to write rA=f(X) so that I can solve for X in my problem
Stephen23
Stephen23 on 16 Sep 2014
Edited: Stephen23 on 16 Sep 2014
Do you have a license for the Curve Fitting Toolbox? If not, this would explain that error message. polyfit is a basic MATLAB function, so it is always available.
"...the polynomial behavior is not really the same...": I might as well repeat the message again. There is NO magic tool to solve your problem, the polynomial plot will be different to your data, unless you know something about the underlying system, and can specify an appropriate function to fit to the data. Only you can answer the question "Can a power 2 polynomial model my data?". If you have some kind of asymptote in your data, then perhaps you should consider this as "knowledge" about the underlying system, and fit some kind of asymptotic curve, via least squares.
Rick
Rick on 16 Sep 2014
Edited: Rick on 16 Sep 2014
I don't have the curve fitting toolbox.
I don't know any underlying information that will tell me how this function will behave. I just have data and plotted it, which is in my first post.
Is there some way to fit other types of curves, other than polynomials? Maybe exponential fit, square root fit, etc?
This is all I have to go on
rA = [-0.2 -0.0167 -0.00488 -0.00286 -0.00204];
X = [0 0.1 0.4 0.7 0.9];
plot(X,rA/60)
the division by 60 is to make the units from minutes to seconds. Now I just need some function that will fit the data given.
Also, there is no need to repeat yourself regarding the magic tool. As I respond you are editing your old posts, I know I wont get something that will exactly fit the data, but I'm trying to find something as close as I can get. This is not a well defined function of X, as you may have guessed.
I just noticed that it seems to asymptote towards 0, if you just look at the data you will see what I mean. How would I fit an asymptotic curve with least squares?
Rick
Rick on 16 Sep 2014
Edited: Rick on 16 Sep 2014
I think a logarithmic function would be more appropriate, but how would I fit it to find the multiplier that will best fit my data? Or even the best log base to fit the data.
I looked at the curve fitting toolbox, but it says students are not allowed to have it. It suggests using the simulink, which I apparently did purchase with my student edition. How would I use that to do this curve fit?
After all this trouble, I just realized that Excel can do this way easier, it will fit the data for me...how hard can it be for MATLAB to do the same thing as excel?!?
Now that I got my fit, how would I do this with MATLAB if I don't pay for the extra curve fitting toolbox.
Of course MATLAB has of non-linear curve fitting tools. An internet search engine can help you find them.
"Also, there is no need to repeat yourself regarding the magic tool"... except that no one else knows what criteria are required for "an equation that represents this non-linear plot", how complicated it needs to be, or how it should behave with data points outside those you have given. I cannot know this, no one else on the forum can know this, and MATLAB also cannot know this. MATLAB is a great numeric tool, and it is up to the user to know their own problem, and know the kind of solution that they require.
I understand that you are trying to figure out a way to parametrize some curve, but essentially it is a problem of inventing data... which, in appropriate circumstances (such as when the underlying model is well understood), can produce useful results.
Your original question was "How would I be able to find an equation that represents this non-linear plot,", to which I gave several suggestions of how you can find functions that represent this data, such as with splines, polyfit, etc.
It seems that perhaps you are actually trying to do something else: identify the most suitable mathematical function (i.e. identify the underlying process) for your data. Is this correct?
Rick
Rick on 20 Sep 2014
Edited: Rick on 20 Sep 2014
Well, I don't see how they are not one of the same animal. Of course the most suitable mathematical function should best fit the data. This data is monotonic, so a polynomial is not going to be a correct fit. I think a logarithm will better fit the data.
Is there something like logfit, analogous to polyfit??
They are a completely different kind of animal. Just like analytic and numeric calculations, they only bear a passing relation to one another.
"Of course the most suitable mathematical function should best fit the data" sounds nice, but in the real world this is hardly guaranteed. It really depends what you mean by "fit": all data measurements are subject to errors, as are the calculations based on them. For any finite set of data values there are going to be precisely an infinite number of functions that could fit it. How on earth should any program "know" that your data is exponential, or linear, or any other convenient function?
"Also, there is no need to repeat yourself regarding the magic tool", sorry, but there is NO magic tool that can identify what function exactly describes the underlying system of behavior of some set of data.

Sign in to comment.

More Answers (1)

Alex Sha
Alex Sha on 4 Jun 2019
The model function below is good enough, also very simple:
rA = 1/(p1+p2*x);
Root of Mean Square Error (RMSE): 0.000219178990662495
Sum of Squared Residual: 2.4019714973915E-7
Correlation Coef. (R): 0.999997155861087
R-Square: 0.999994311730263
Adjusted R-Square: 0.999988623460527
Determination Coef. (DC): 0.999992008454451
Chi-Square: -2.91785095249027E-5
F-Statistic: 375968.944829523
Parameter Best Estimate
---------- -------------
p1 -5.00002149728568
p2 -543.303262063525
c174.jpg

Categories

Tags

Asked:

on 16 Sep 2014

Answered:

on 4 Jun 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!