Rational function produced by the Curve Fitter App does not match the output graph

조회 수: 13 (최근 30일)
I am trying to model a line in MATLAB using the Curve Fitting Toolbox. I have input the data into the toolbox, and would like to use a rational function to model the data (either rat55 or rat54 work well). I have attached the csv file for the data I would like to curve fit with. The function which MATLAB produces for rat55 with 'center and scale' ticked is as follows
function [fitresult, gof] = fn_c1(c1y, c1x)
%CREATEFIT(C1Y,C1X)
% Create a fit.
%
% Data for 'fn_c1' fit:
% X Input: c1y
% Y Output: c1x
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 21-Nov-2023 11:50:01
%% Fit: 'fn_c1'.
[xData, yData] = prepareCurveData( c1y, c1x );
% Set up fittype and options.
ft = fittype( 'rat55' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Normalize = 'on';
opts.StartPoint = [0.284293074456312 0.435315805784207 0.903759051181981 0.925105644987009 0.505292452205831 0.62758180927003 0.71926392682241 0.0239128813596552 0.5749325019969 0.0465344640640383 0.422531388268483];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
coeffvalues(fitresult)
% Plot fit with data.
figure( 'Name', 'fn_c1' );
h = plot( fitresult, xData, yData );
axis([0.1 10000 10 10000])
legend( h, 'c1x vs. c1y', 'fn_c1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'c1y', 'Interpreter', 'none' );
ylabel( 'c1x', 'Interpreter', 'none' );
grid on
xscale log
yscale log
And this produces the following graph. It should be noted I DO want c1x on the vertical axis and c1y on the horizontal.
The model suggests that the following equation should represent the graph, but it is not anywhere near being close when I put this into Excel or Desmos.
General model Rat55:
ans(x) =
(p1*x^5 + p2*x^4 + p3*x^3 + p4*x^2 + p5*x + p6) /
(x^5 + q1*x^4 + q2*x^3 + q3*x^2 + q4*x + q5)
where x is normalized by mean 1544 and std 2429
Coefficients (with 95% confidence bounds):
p1 = 35.72 (33.59, 37.85)
p2 = 101.7 (98.68, 104.7)
p3 = 115.2 (110.2, 120.2)
p4 = 65.83 (61.06, 70.6)
p5 = 18.99 (16.97, 21.01)
p6 = 2.209 (1.894, 2.524)
q1 = 2.766 (2.698, 2.834)
q2 = 3.059 (2.902, 3.216)
q3 = 1.692 (1.558, 1.826)
q4 = 0.4683 (0.4175, 0.5191)
q5 = 0.0519 (0.0447, 0.05911)
Hoping somebody knows why the equation provided does not represent the graph given at all. My guess is that it is something to do with normalization, but how would I format this equation in some sort of graphing calculator so that it can be produced like it is from the MATLAB function. I have attached the c1 data, and in my example the following code produces the graph
c1 = readtable('c1.csv');
c1x = c1.x
c1y = c1.y
fn_c1(c1y, c1x)
Thanks

답변 (1개)

Torsten
Torsten 2023년 11월 22일
편집: Torsten 2023년 11월 22일
Look up the documentation to see what the option
opts.Normalize = 'on';
means.
The coefficients are used to approximate y vs (x-mean(x))/std(x). Thus you have to make the backtransformation to plot y vs x.
y = (p1*x'^5 + p2*x'^4 + p3*x'^3 + p4*x'^2 + p5*x' + p6) / (x'^5 + q1*x'^4 + q2*x'^3 + q3*x'^2 + q4*x' + q5)
where x' = (x-mean(x))/std(x).
You may multiply out and collect to get new coefficients for the "unnormalized" representation
y = (p1'*x^5 + p2'*x^4 + p3'*x^3 + p4'*x^2 + p5'*x + p6') / (x^5 + q1'*x^4 + q2'*x^3 + q3'*x^2 + q4'*x + q5')

카테고리

Help CenterFile Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by