Fitting an exponential equation to this data with CFtool

4 visualizzazioni (ultimi 30 giorni)
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 Commento
Torsten
Torsten il 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.

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 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 Commento
Sam Chak
Sam Chak il 1 Nov 2023
It's a nice prediction plot. With the ±95% confidence interval relatively wide, OP should consider obtaining more data.

Accedi per commentare.

Più risposte (1)

Sam Chak
Sam Chak il 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 Commenti
Torsten
Torsten il 1 Nov 2023
Do you think y(0) = 2818 according to the data given ?
Sam Chak
Sam Chak il 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:

Accedi per commentare.

Categorie

Scopri di più su Time and Frequency Domain Analysis in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by