Fitting an exponential equation to this data with CFtool
2 views (last 30 days)
Show older comments
Hello,
I have the following points:
y=[10 80 120 180 280 415 680 972 1178 1322 1445];
t=[50 300 410 600 900 1190 1797 2400 3000 3600 4985];
and they should fit an equation which has the form of
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1526626/image.png)
I have problems with inputting this equation into cftool. My scope is to find a suitable range for all the coefficient, which, in theory, should all be positive values.
Any help is much appreciated.
Stefano
1 Comment
Torsten
on 1 Nov 2023
What are the coefficients you want to fit in your equation ?
As t -> Inf, your equation tends to y(0). But this is not consistent with the trend of your data curve.
Accepted Answer
Star Strider
on 1 Nov 2023
y=[10 80 120 180 280 415 680 972 1178 1322 1445];
t=[50 300 410 600 900 1190 1797 2400 3000 3600 4985];
objfcn = @(b,x) b(1).*(1-exp(b(2).*x./b(1)))
nlmdl = fitnlm(t, y, objfcn, [max(y);randn])
tv = linspace(min(t), max(t)).';
[yr,yci] = predict(nlmdl, tv);
figure
hp1 = plot(t, y, 'pb', 'MarkerFaceColor','b', 'DisplayName','Data');
hold on
hp2 = plot(tv, yr, '-r','DisplayName','Regression');
hp3 = plot(tv, yci, ':r','DisplayName','\pm95% Confidence Interval');
hold off
grid
legend([hp1 hp2 hp3(1)], 'Location','best')
tv = linspace(min(t), 10*max(t)).';
[yr,yci] = predict(nlmdl, tv);
figure
hp1 = plot(t, y, 'pb', 'MarkerFaceColor','b', 'DisplayName','Data');
hold on
hp2 = plot(tv, yr, '-r','DisplayName','Regression');
hp3 = plot(tv, yci, ':r','DisplayName','\pm95% Confidence Interval');
hold off
grid
legend([hp1 hp2 hp3(1)], 'Location','best')
.
1 Comment
Sam Chak
on 1 Nov 2023
It's a nice prediction plot. With the ±95% confidence interval relatively wide, OP should consider obtaining more data.
More Answers (1)
Sam Chak
on 1 Nov 2023
The data doesn't show the steady-state value. Nonetheless, we can still try fitting the exponential model to the data. I believe that the exponential model may be relatively inaccurate for fitting only a portion of the transient response.
% Data
tdat = [50 300 410 600 900 1190 1797 2400 3000 3600 4985];
ydat = [10 80 120 180 280 415 680 972 1178 1322 1445];
% Proposed exponential model with coefficients a1 and a2
yfit = @(a, tdat) a(1)*(1 - exp(- a(2)/a(1)*tdat));
% The algorithm starts with the initial guess of coefficients a1 and a2
a0 = [2*max(ydat) 1];
% Call lsqcurvefit to fit the model
[asol, resnorm] = lsqcurvefit(yfit, a0, tdat, ydat)
% Computing the Coefficient of determination
ybar = mean(ydat);
dev = ydat - ybar;
Sdev = sum(dev.^2);
Rsq = (Sdev - resnorm)/Sdev % R-square
% Plot fitting result
plot(tdat, ydat, 'bo', tdat, yfit(asol, tdat), 'r-'), grid on
legend('Data points', 'Fitted curve', 'location', 'best')
xlabel('t'), ylabel('y')
title({'$y(t) = a_{1} (1 - \exp(- \frac{a_{2}}{a_{1}} t))$'}, 'interpreter', 'latex', 'fontsize', 16)
2 Comments
Sam Chak
on 1 Nov 2023
Unfortunately, @Stefano Russo's data doesn't show the initial value y(0). If the response follows a 1st-order linear time-invariant system,
, then the initial value y(0) is most likely 0. However, I took a guess that OP intended to fit an exponential model. Technically, the general analytical solution for 1st-order LTI systems is given by:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1526966/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1526971/image.png)
If u = 1 and y(0) = 0, then the ideal solution becomes:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1526976/image.png)
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!