![0000 Screenshot.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253468/0000%20Screenshot.png)
Fitting Data to a Non-Linear Curve
1 次查看(过去 30 天)
显示 更早的评论
I have matrix data for x and y and am looking to find an equation that best represents this data. We don't believe it is a polynomial line of best fit so polyfit wouldn't be appropriate. Is there a method for finding the equation for logarithmic or exponential through data?
Here's the data for reference:
x=[0 1 2 3 4 5 6 7 8 9 10]
y=[.0242 0.1940 0.2792 0.2358 0.1386 0.0598 0.0238 0.0090 0.0034 0.0013 0.002]
1 个评论
Image Analyst
2019-12-8
Looks like it could either be log-normal, or the sum of two normals. Is there some knowledge you have about the physics of the situation that might lead you to prefer one or the other, or even some other equation? What physical process gave rise to these measurements?
x=[0 1 2 3 4 5 6 7 8 9 10]
y=[.0242 0.1940 0.2792 0.2358 0.1386 0.0598 0.0238 0.0090 0.0034 0.0013 0.002]
plot(x, y, 'bs-');
grid on;
![0000 Screenshot.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253468/0000%20Screenshot.png)
I can fit the data to either equation with fitnlm() though with only 10 data points, it will be difficult to definitively state that one is better than the other because the sum of the residuals is less. You'd need many more data points to be more certain which is better.
采纳的回答
Star Strider
2019-12-8
One possibility:
x=[0 1 2 3 4 5 6 7 8 9 10];
y=[.0242 0.1940 0.2792 0.2358 0.1386 0.0598 0.0238 0.0090 0.0034 0.0013 0.002];
objfcn = @(b,x) b(1).*x.*exp(b(2).*x);
B0 = [1; -1];
[B,rsdnrm] = fminsearch(@(b) norm(y - objfcn(b,x)), B0);
xv = linspace(min(x), max(x));
figure
plot(x, y, 'pg')
hold on
plot(xv, objfcn(B,xv), '-r')
hold off
grid
text(4.5, 0.22, sprintf('$y(x) = %.3f \\cdot x \\cdot e^{%+0.3f \\cdot x}$',B), 'Interpreter','latex')
xlabel('x')
ylabel('y(x)')
The most accurate model would be one that models the process that created your data.
This model produces:
![1Fitting Data to a Non-Linear Curve1Fitting Data to a Non-Linear Curve - 2019 12 07.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253469/1Fitting%20Data%20to%20a%20Non-Linear%20Curve1Fitting%20Data%20to%20a%20Non-Linear%20Curve%20-%202019%2012%2007.png)
0 个评论
更多回答(1 个)
Alex Sha
2019-12-9
If don't care the function type, the follow is one:
y = p1*(p2^x)*(x+p3)^p4;
Root of Mean Square Error (RMSE): 0.0032240913289773
Sum of Squared Residual: 0.000114342413873453
Correlation Coef. (R): 0.999488278914727
R-Square: 0.998976819687923
Adjusted R-Square: 0.998721024609904
Determination Coef. (DC): 0.998955740196223
Chi-Square: 0.00189307571492163
F-Statistic: 2218.55228360604
Parameter Best Estimate
---------- -------------
p1 0.0382808254972641
p2 0.190470576993248
p3 0.932820554835385
p4 4.94812019020198
![c240.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253539/c240.jpeg)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!