Problem in curve fitting using curvefitter app
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Shashi Kiran
il 20 Set 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.
Risposte (1)
Sam Chak
il 20 Set 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)
%% Plot results
plot(yfit, x, y), grid on
xlabel('t'), ylabel('x(t)')
legend('Data', 'Fitted model')
5 Commenti
Alex Sha
il 21 Set 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
il 21 Set 2024
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)
c = yfit.c
Vedere anche
Categorie
Scopri di più su Linear and Nonlinear Regression in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!