plot sfit shows an offset between data and the fit but the residuals are very small.
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have been trying to fit my data to a custom function with 10 fitting parameters using
% [fitres,gof] = fit( [xData, yData], zData, ft, opts )
where ft is the custom function I defined, opts specifies the parameter bounds, initial guess, fitting method and the stop criteria. I can plot the fitting results as follows
plot(fitres,[xData yData],zData)
which generates the figure below
There is clearly an overall offset between the data and fit. But we could check the goodness of fit
gof =
struct with fields:
sse: 0.0576
rsquare: 0.9850
dfe: 269
adjrsquare: 0.9845
rmse: 0.0146
and also the residuals plot
plot(fitres,[xData yData],zData,'Style','residuals')
I can also plot fit results with the data manually using surf
surf(reshape(feval(fitres,[xData yData]),[31 9]),'linestyle','none')
hold on
surf(reshape(zData,[31 9]),'facecolor','none')
where the solid surface is the fit, the grid is the data.
All of the three tests above showed a relatively reasonable agreement between the data and the fit. Can anyone help to explain the problem with the plot(fitres,[xData yData],zData) function?
The data can be found in the attachment.
9 Commenti
the cyclist
il 19 Mar 2023
It's a mystery to me. If I extract the fit coefficients from the fitres object, and manually plot, it show them close together:
load test_data
Def = 0.2908;
gmf = 1077;
lossf = 0.02632;
lossother = 1.303;
losstls = 0.6968;
mu = 0.7957;
t1f = 4.784e+06;
t2f = 0.001997;
tmin = 0.006372;
vol = 60.73;
figure
hold on
scatter3(xData,yData,zData)
scatter3(xData,yData,tls_full_fit(xData,yData,lossf,losstls,lossother,t2f,t1f,gmf,vol,Def,mu,tmin))
view(-45,30)
Risposta accettata
Matt J
il 20 Mar 2023
Modificato: Matt J
il 20 Mar 2023
One thing that seems to be creating problems is that your model function returns different results depending on whether the (x,y) pairs given to it are vectors or scalars. This violates the assumptions of the Curve Fitting Toolbox. The model function is supposed to be a point-wise operation. In other words, the use of mdl(X,Y) or arrayfun(mdl,X,Y) below is supposed to give the same result, but does not:
load('test_data.mat')
Def = 0.2908;
gmf = 1077;
lossf = 0.02632;
lossother = 1.303;
losstls = 0.6968;
mu = 0.7957;
t1f = 4.784e+06;
t2f = 0.001997;
tmin = 0.006372;
vol = 60.73;
[X,Y]=deal(xData,yData);
mdl= @(x,y)tls_full_fit(x,y,lossf,losstls,lossother,t2f,t1f,gmf,vol,Def,mu,tmin);
discrepancy = max(abs( mdl(X,Y) - arrayfun(mdl,X,Y) ) )
1 Commento
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with Curve Fitting Toolbox 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!