![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/657685/image.jpeg)
Best equation for Curve Fitting
2 views (last 30 days)
Show older comments
Can someone give me the best equation for fitting this curve
clc
close all
clear all
% Shear Stress Data (tau)
x = [0 0.004451043 0.038688186 0.735062819 0.782019317 1.594521919 1.642507629 2.59312869 2.643649113 3.753413617 3.808892339 5.101477848 5.161995222 6.596302962 6.657818541 8.139665372 8.202526359 9.683129426 9.748762511 11.19273216 11.25754175 12.53313276 12.59651093 13.69044727 13.75079095 14.68565326];
x = x*10^-3; % converting to meters
y = [-1.66E+07 -1.65E+07 -1.62E+07 -1.02E+07 -1.01E+07 -6868466.274 -6778223.204 -5199368.229 -5166179.72 -4430907.666 -4420065.933 -4168450.441 -4168500.008 -4167024.178 -4172591.221 -4306588.629 -4318151.713 -4594452.961 -4624282.626 -5296317.693 -5366938.191 -6848554.377 -7016084.319 -1.02E+07 -1.08E+07 -2.07E+07];
fcn = @(b,x) b(1)+ b(2).*x - b(3).*exp(-b(4)*x); % suggest a better equation please
B0 = rand(4,1);
B = lsqcurvefit(fcn, B0, x, y)
figure
plot(x, y, 'p')
hold on
plot(x, fcn(B,x), '-r')
hold off
grid
xlabel('X')
ylabel('Y')
%legend('Data', sprintf('y = %.3f\\cdotx^{%.3f}', B), 'Location','E')
I want to capture the data points as precisely as possible, it doesn't matter if equation is complex.
1 Comment
Alex Sha
on 18 Jun 2021
The equation below seems to be good enough:
y = 1/(p1*sin(p2*x+p3))+p4*x+p5
Root of Mean Square Error (RMSE): 165925.431217479
Sum of Squared Residual: 715812466842.366
Correlation Coef. (R): 0.999366806323172
R-Square: 0.998734013580577
Parameter Best Estimate
---------- -------------
p1 3.28885892497527E-7
p2 190.268111842121
p3 -2.95337291125282
p4 -71910402.0440169
p5 -449707.42534779
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/657685/image.jpeg)
Answers (1)
Scott MacKenzie
on 18 Jun 2021
Edited: Scott MacKenzie
on 19 Jun 2021
How about r = .9999?
Linear model Poly9:
f(x) = p1*x^9 + p2*x^8 + p3*x^7 + p4*x^6 +
p5*x^5 + p6*x^4 + p7*x^3 + p8*x^2 + p9*x + p10
Coefficients (with 95% confidence bounds):
p1 = -1.997e+26 (-3.775e+26, -2.186e+25)
p2 = 9.985e+24 (-1.688e+24, 2.166e+25)
p3 = -1.829e+23 (-5.031e+23, 1.372e+23)
p4 = 1.157e+21 (-3.601e+21, 5.914e+21)
p5 = 7.562e+18 (-3.392e+19, 4.904e+19)
p6 = -1.788e+17 (-3.934e+17, 3.592e+16)
p7 = 1.324e+15 (6.891e+14, 1.958e+15)
p8 = -5.242e+12 (-6.207e+12, -4.277e+12)
p9 = 1.177e+10 (1.118e+10, 1.236e+10)
p10 = -1.66e+07 (-1.668e+07, -1.651e+07)
Goodness of fit:
SSE: 7.084e+10
R-square: 0.9999
Adjusted R-square: 0.9998
RMSE: 6.654e+04
This is a bit of an odd question. It's a bit like asking, Can someone tell me what the best song is? Really, by what criteria? If the only criterion for the question herein is achieving the highest r (or R-squared), then the question is unanswerable, since for any proposed equation and very high r, you can always just add more terms to get an even higher r.
0 Comments
See Also
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!