How to extrapolate the data
35 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
sandeep
le 5 Sep 2022
Réponse apportée : Star Strider
le 5 Sep 2022
I have a dataset of degadation of a battery. As you can see in the picture,i have fitted that data to a custom equation
[1-(0.5*k1*x^2+k2*x)-k3/3242.752734*3502] using curve fitter app. so that i got the coefficient values in the equation.
my qestion is how to extrapolate this data, to see the points outside the data and the respective coefficient values.attached you can find my data set. also find the generated code from curvefitter app.
I appreciate any help.
load('https://de.mathworks.com/matlabcentral/answers/uploaded_files/1117125/DATA.mat');
%% Fit: 'capacity@25'.
[xData, yData] = prepareCurveData( cycleNumber, NormalizedSOH );
% Set up fittype and options.
ft = fittype( '1-(0.5*k1*x^2+k2*x)-k3/3242.752734*3502', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.57970458736557 0.549860201836332 0.144954798223727];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'capacity@25' );
h = plot( fitresult, xData, yData );
legend( h, 'NormalizedSOH vs. cycleNumber', 'capacity@25', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'cycleNumber', 'Interpreter', 'none' );
ylabel( 'NormalizedSOH', 'Interpreter', 'none' );
grid on
0 commentaires
Réponse acceptée
Star Strider
le 5 Sep 2022
Another approach —
load(websave('DATA','https://de.mathworks.com/matlabcentral/answers/uploaded_files/1117125/DATA.mat'));
%% Fit: 'capacity@25'.
[xData, yData] = prepareCurveData( cycleNumber, NormalizedSOH );
% Set up fittype and options.
ft = fittype( '1-(0.5*k1*x^2+k2*x)-k3/3242.752734*3502', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.57970458736557 0.549860201836332 0.144954798223727];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
x_new = linspace(min(xData)-50, max(xData)+50, 500).'; % X-Values For Extrapolation
[ci,y_new] = predint(fitresult, x_new); % Extrapolate & Return Confidence Intervals
% Plot fit with data.
figure( 'Name', 'capacity@25' );
h = plot( fitresult, xData, yData );
hold on
plot(x_new, y_new, '--m', 'DisplayName','Extrapolated Values')
plot(x_new, ci, ':m', 'DisplayName','Confidence Intervals')
hold off
legend( h, 'NormalizedSOH vs. cycleNumber', 'capacity@25', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'cycleNumber', 'Interpreter', 'none' );
ylabel( 'NormalizedSOH', 'Interpreter', 'none' );
grid on
.
0 commentaires
Plus de réponses (1)
John D'Errico
le 5 Sep 2022
Modifié(e) : John D'Errico
le 5 Sep 2022
Your model is only a quadratic polynomial. Why you needed to use a nonlinear regression is beyond me, when polyfit would have worked. Regardless, you did do that.
Extrapolating a quadratic polynomial is often a bad idea, certainly an extrapolation that goes far out. Extrapolate anythign too far, and you will get garbage.
And since we do not have your function prepareCurveData, we cannot even help you more.
However, you can use that result to evaluate your function. For example:
x = rand(10,1);y = sin(2*x) + randn(size(x))/20;
fittedmdl = fit(x,y,'poly2')
Here, I have intentionally fit the curve with a quadratic polynomial, despite the fact that I know it was a sine function underneath.
plot(fittedmdl)
hold on
plot(x,y,'o')
hold off
Now we can evaluate the model at any point. Note the function was fit on a region of support [0,1]. But you can predict the value of that function at points outside that domain of support.
fittedmdl(1.5)
fittedmdl(3)
As you can see, if we try to extrapolate that model out too far, then we get nonsensical garbage.
3 commentaires
John D'Errico
le 5 Sep 2022
Modifié(e) : John D'Errico
le 5 Sep 2022
I showed you how to evaluate the function, at ANY point you desire.
ypredicted = fitresult(x)
Voir également
Catégories
En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!