Fitting an exponential equation to this data with CFtool
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Torsten
2023 年 11 月 1 日
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.
採用された回答
Star Strider
2023 年 11 月 1 日
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 件のコメント
Sam Chak
2023 年 11 月 1 日
It's a nice prediction plot. With the ±95% confidence interval relatively wide, OP should consider obtaining more data.
その他の回答 (1 件)
Sam Chak
2023 年 11 月 1 日
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 件のコメント
Sam Chak
2023 年 11 月 1 日
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:

参考
カテゴリ
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!