![0000 Screenshot.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253468/0000%20Screenshot.png)
Fitting Data to a Non-Linear Curve
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Andrew Rowe
am 8 Dez. 2019
Beantwortet: Alex Sha
am 9 Dez. 2019
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 Kommentar
Image Analyst
am 8 Dez. 2019
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.
Akzeptierte Antwort
Star Strider
am 8 Dez. 2019
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 Kommentare
Weitere Antworten (1)
Alex Sha
am 9 Dez. 2019
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 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!