Problem in curve fitting using curvefitter app

3 views (last 30 days)
I am trying to curvefit some data on a customised exponential equation: y=A*exp(-(x-x0)/t) using curvefitter application in MATLAB.
While doing so, for x ranging from 30 to 70, the curvefitter is not able to curve fit though I was able to do the same when I was using the equation y=A*(1-exp(-(x-x0)/t)) when x ranges from 70 to 80.
Also, the curvefitting was successful when I tried to curvefit for the equation y=A*(1-exp(-x/t)), x0 being omitted here because the starting point is of x is 0 and x ranges from 0 to 30.
For the curvefitting, A, t and x0 are the parameters to be found by curvefitting the data.
x0 is close to the starting point of x, it is being included to avoid very large exponent values.
The curvefitter is giving a horizontal line only.
I have attached images for both cases.
Case 1:
Case 2:
Case 3:
  8 Comments
Shashi Kiran
Shashi Kiran on 20 Sep 2024
Try adding a constant term to the custom equation and set intial alue of x0 to 30(as x starts from 30) as shown.
This helps in corrrect fit.
Farkhanda Azmi
Farkhanda Azmi on 20 Sep 2024
Edited: Farkhanda Azmi on 20 Sep 2024
Thank you for your response, is there any way to fit it without using constant term? I know that it may need a constant term but I am trying to simply keep one exponent term only. Because for previous cases, as shared in the images attached, I was able to do it roughly without using the constant term.

Sign in to comment.

Answers (1)

Sam Chak
Sam Chak on 20 Sep 2024
I fitted the data using a logarithm function:
%% Data
load('yvalues_curvefit_case.mat');
y = y3a_DOD_dot1;
x = linspace(30, 70, numel(y))';
%% Fitting model
fo = fitoptions('Method', 'NonlinearLeastSquares',...
'Lower', [0.01, 200, 28, 0.21, 85, 1.03],...
'Upper', [0.03, 220, 30, 0.23, 95, 1.05],...
'StartPoint', [0.02, 210, 29, 0.22, 90, 1.04]);
ft = fittype('a*log(b*(x - c)^d + e*(x - c)^f)', ...
'dependent', {'prob'}, 'independent', {'x'}, ...
'coefficients', {'a', 'b', 'c', 'd', 'e', 'f'}, ...
'options', fo);
%% Fit curve to data
[yfit, gof] = fit(x, y, ft)
yfit =
General model: yfit(x) = a*log(b*(x - c)^d + e*(x - c)^f) Coefficients (with 95% confidence bounds): a = 0.02118 (0.01775, 0.02461) b = 207.9 (9.807, 405.9) c = 30 (30, 30) d = 0.2246 (0.1566, 0.2927) e = 85.89 (13.01, 158.8) f = 1.035 (0.892, 1.179)
gof = struct with fields:
sse: 1.1873e-05 rsquare: 0.9999 dfe: 394 adjrsquare: 0.9999 rmse: 1.7360e-04
%% Plot results
plot(yfit, x, y), grid on
xlabel('t'), ylabel('x(t)')
legend('Data', 'Fitted model')
  5 Comments
Alex Sha
Alex Sha on 21 Sep 2024
@Sam Chak: the fitting function of "a*log(b*(x - c)^d + e*(x - c)^f)" gives wonderful result, however, the best solution will be as fellow, the objective function value of SSE is little better, but with much different parameters:
Sum Squared Error (SSE): 2.3362432323886E-6
Root of Mean Square Error (RMSE): 7.64238711462033E-5
Correlation Coef. (R): 0.999988328851169
R-Square: 0.999976657838553
Parameter Best Estimate
--------- -------------
a 0.00767031100705701
b 5971471.14414276
c 30.0935323605759
d 1.00821070650148
e 911138.477416586
f 2.54707754950121
Sam Chak
Sam Chak on 21 Sep 2024
Hey @Alex Sha,
Thank you for providing the values with a better sum of squared errors. I forgot to mention to the OP (@Farkhanda Azmi) that the constraint for parameter c should be less than 30 (), rather than exactly 30, as displayed due to rounding. The reason for this is that the data begins at , and the initial value of should be finite. If , then the fitting function will produce complex values.
Another candidate function is the surd function; however, I did not conduct a more thorough investigation.
format long g
%% Fit curve to data
[yfit, gof] = fit(x, y, ft)
yfit =
General model: yfit(x) = a*log(b*(x - c)^d + e*(x - c)^f) Coefficients (with 95% confidence bounds): a = 0.02118 (0.01775, 0.02461) b = 207.9 (9.807, 405.9) c = 30 (30, 30) d = 0.2246 (0.1566, 0.2927) e = 85.89 (13.01, 158.8) f = 1.035 (0.892, 1.179)
gof = struct with fields:
sse: 1.18733567720894e-05 rsquare: 0.999881369453811 dfe: 394 adjrsquare: 0.999879863990027 rmse: 0.000173595573905024
c = yfit.c
c =
29.998908662656

Sign in to comment.

Categories

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!