How to extrapolate the data
조회 수: 33 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2022년 9월 5일
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
추가 답변 (1개)
John D'Errico
2022년 9월 5일
편집: John D'Errico
2022년 9월 5일
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
John D'Errico
2022년 9월 5일
편집: John D'Errico
2022년 9월 5일
I showed you how to evaluate the function, at ANY point you desire.
ypredicted = fitresult(x)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!