Why is the power1 fit seemingly so bad compared to Excel?
Show older comments
I'm using MATLAB 2023b and the fitobject function. I have a set of data that is 162 points which I load into the script via a .mat file. I plot the data on a loglog scale and fit the data using power1 and return a gof to me. The rsquare is only 0.6473 and when I plot the fit with my data the fit looks terrible. I took this same data and plotted it in excel, then used excel's trendline tool and a power fit and am seemingly getting a much better fit (rsquare=0.83) the values for a and b are also very different (a=1e-10, b=2.4335). To show the differences in the two fits I did the curve fitting in MATLAB and plotted it, then added the fit equation given by Excel to the same plot and this is what I am getting:

Here is the code in text form to copy but I can't include my actual data:
clc;
%Find c and m constants using the Paris power law
load dadN_K_CCV2_5a_ad.mat
x = dadN_K_CCV2_5a_ad(:,2);
y = dadN_K_CCV2_5a_ad(:,1);
loglog(x,y,'s',MarkerFaceColor="b")
grid on
hold on
[fitobject,gof]=fit(x,y,'power1') %fitobject returns a and b which correlate to C and m respectively
plot(fitobject)
xlabel("delta K")
ylabel("da/dN")
x1 = 1:.1:10;
y1 = 1e-10.*x1.^2.4335; %fit given by Excel's power fit
plot(x1,y1)
hold off;
I need to use the coefficients given by this fit elsewhere so it is important that they are accurate. I would like to do everything in MATLAB but I can't justify the difference in fit from Excel. Am I missing something? Thanks in advance!
2 Comments
John D'Errico
on 9 Feb 2024
You don't actually include the data, so we cannot show you what happens when the fit is done as we think it should be.
Why not make it possible to get help? Do you really want to make it more difficult for someone to help you?
"Am I missing something?"
Yes, Excel actually does something else, it does not obtain the least squares fit of a power curve:
Question for anyone who knows: is there a FIT model that replicates the Excel approach?
Answers (1)
Most probably, Excel fitted log(y) against log(a)+b*log(x). If you plot the result in logscale, this might look great. But you have to compare the two fits in usual plot scale.
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!