Fitting an exponential equation to this data with CFtool

2 views (last 30 days)
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
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
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.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 1 Nov 2023
I get this result with fitnlm
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)))
objfcn = function_handle with value:
@(b,x)b(1).*(1-exp(b(2).*x./b(1)))
nlmdl = fitnlm(t, y, objfcn, [max(y);randn])
nlmdl =
Nonlinear regression model: y ~ b1*(1 - exp(b2*x/b1)) Estimated Coefficients: Estimate SE tStat pValue ________ ________ _______ __________ b1 2818.1 796.96 3.536 0.0063535 b2 -0.45067 0.044962 -10.023 3.5094e-06 Number of observations: 11, Error degrees of freedom: 9 Root Mean Squared Error: 83.5 R-Squared: 0.978, Adjusted R-Squared 0.976 F-statistic vs. zero model: 493, p-value = 6.35e-10
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
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.

Sign in to comment.

More Answers (1)

Sam Chak
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)
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
asol = 1×2
1.0e+03 * 2.8182 0.0005
resnorm = 6.2679e+04
% Computing the Coefficient of determination
ybar = mean(ydat);
dev = ydat - ybar;
Sdev = sum(dev.^2);
Rsq = (Sdev - resnorm)/Sdev % R-square
Rsq = 0.9782
% 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
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:
If u = 1 and y(0) = 0, then the ideal solution becomes:

Sign in to comment.

Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!