How to plot a best fit curve to my data points?
Show older comments
Hi,
I have attached a data (inverted_qp.mat Inv_qpAVO freq;) and a plot between fre and Inv_qpAVO is shown below in red color.
circled points on left hand side are the issue and I want to a best-fit curves passes through these points just like shown on the right hand side figure (in blue color a solid line).
The best fit curve should start from the fist point to the end point as given a solid blue line. Thanks

7 Comments
Nisar Ahmed
on 2 Jun 2022
Alex Sha
on 3 Jun 2022
Try the model below:
y = p1+p2*x+p3*x^1.5+p4*log(x)+p5*exp(p6*x)
Sum Squared Error (SSE): 1.59130623291519E-6
Root of Mean Square Error (RMSE): 0.00031536746749974
Correlation Coef. (R): 0.970802539336279
R-Square: 0.942457570381768
Adjusted R-Square: 0.93360488890204
Determination Coef. (DC): 0.942457570381768
Chi-Square: 0.000179198129320299
F-Statistic: 32.7569613131459
Parameter Best Estimate Std. Deviation Confidence Interval[95%]
--------- ------------- -------------- -------------------
p1 -0.137921750658333 0.174070650978335 [-0.525775331093703, 0.249931829777037]
p2 4.83156544429652E-5 6.41506994605273E-5 [-9.46210114071306E-5, 0.000191252320293061]
p3 -3.87422699831525E-7 5.2372155346116E-7 [-1.55434704072094E-6, 7.79501641057892E-7]
p4 0.000904269701487609 0.000207649174901467 [0.000441598507306757, 0.00136694089566846]
p5 0.138139976684668 0.174107523689351 [-0.249795761270695, 0.526075714640031]
p6 -0.000327312583052385 7.19593900360924E-5 [-0.000487648095757037, -0.000166977070347734]

Sam Chak
on 3 Jun 2022
Bravo, Alex.
One question though. Does anyone with a decent knowledge of math functions be able to intellectually figure out the proposed model?
It's a combination of fractional polynomial, logarithmic function and exponential function.
f(x) = p1 + p2*x + p3*x^1.5 + p4*log(x) + p5*exp(p6*x)
Image Analyst
on 3 Jun 2022
In my opinion you should pick a model that is meaningful and based on some theory. I doubt the physics of the situation has a theoretical model that complicated, but it might. I also doubt the point at 0,0 was a measured point. I think it was just assigned thinking that's what it should be. If it weren't for that point I'd have thought an exponential decay function might be good. If it's a real point, then perhaps some kind of log-normal equation would be good and log-normal is the theoretical equation in a lot of situations. Or maybe a Rayleigh curve. But if it is a log-normal curve then you should get more points between 0 and the peak. How can we get a good fit with so much data missing from a crucial region? Plus there are way too few points out on the right side. Look at the noise around the peak. It's like 20%. But look out on the right side. You just have 3 or 4 points and the curve pretty much goes through them and the curve coefficients are greatly determined by those. If you didn't have those but had some more measured points that were around 20% different than those, the coefficients of the curve would be vastly different. So that's why I don't trust the curve coefficients without getting extra observations on the left side and right side of the plot.
John D'Errico
on 3 Jun 2022
Edited: John D'Errico
on 3 Jun 2022
@Nisar Ahmed Please stop using a new answer every time you want to make a comment.
Sam Chak
on 3 Jun 2022
@Image Analyst, thanks for the insights into the analysis of the data that provides a basis for understanding the curve fitting. 👍
Answers (2)
Kevin Holly
on 2 Jun 2022
0 votes
If you have the Curve Fitting Toolbox, you can use the Curve Fitting app after you import your data into the workspace. Within the app, there are many curve fits you could select from. Here is a video showing the process.
1 Comment
John D'Errico
on 3 Jun 2022
<Moved to a comment from @Nisar Ahmed
Nisar Ahmed
on 3 Jun 2022
0 votes
1 Comment
p(1) = -0.137921750658333;
p(2) = 4.83156544429652E-5;
p(3) = -3.87422699831525E-7;
p(4) = 0.000904269701487609;
p(5) = 0.138139976684668;
p(6) = -0.000327312583052385;
f = @(x)p(1) + p(2)*x + p(3)*x.^1.5 + p(4).*log(x) + p(5).*exp(p(6).*x);
plot(x,f(x))
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!