How to extrapolate the data

35 vues (au cours des 30 derniers jours)
sandeep
sandeep 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');
Error using load
Unable to read file 'https://de.mathworks.com/matlabcentral/answers/uploaded_files/1117125/DATA.mat'. If it is a Version 7 or earlier MAT-file, consider saving your data afresh in Version 7.3
MAT-files to access it from a remote location.
%% 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

Réponse acceptée

Star Strider
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 )
fitresult =
General model: fitresult(x) = 1-(0.5*k1*x^2+k2*x)-k3/3242.752734*3502 Coefficients (with 95% confidence bounds): k1 = 8.938e-08 (5.771e-08, 1.211e-07) k2 = 9.171e-05 (8.858e-05, 9.483e-05) k3 = 0.09297 (0.09285, 0.09309)
gof = struct with fields:
sse: 1.6574e-05 rsquare: 0.9971 dfe: 187 adjrsquare: 0.9971 rmse: 2.9771e-04
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
.

Plus de réponses (1)

John D'Errico
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')
fittedmdl =
Linear model Poly2: fittedmdl(x) = p1*x^2 + p2*x + p3 Coefficients (with 95% confidence bounds): p1 = -1.777 (-2.412, -1.143) p2 = 2.737 (2.086, 3.388) p3 = -0.07414 (-0.241, 0.09272)
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)
ans = 0.0328
fittedmdl(3)
ans = -7.8575
As you can see, if we try to extrapolate that model out too far, then we get nonsensical garbage.
  3 commentaires
Torsten
Torsten le 5 Sep 2022
Modifié(e) : Torsten le 5 Sep 2022
x = 1;
y = feval(fitresult,x)
or simply
y = fitresult(x)
John D'Errico
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)

Connectez-vous pour commenter.

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!

Translated by