Curve fitting with loglog data

조회 수: 16 (최근 30일)
Manny Kins
Manny Kins 2021년 8월 6일
댓글: Star Strider 2021년 8월 9일
I am having some issues fitting a curve using polyfit to log data. I think I am making a silly mistake during the fit plotting as the fitting is really bad during the beggining but can't seem to figure it out. Any help would be greatly appreciated! I have attached the data as: msd_help
load('msd_help')
figure()
loglog(s,m)
hold on
linearCoefficients = polyfit((s),(m), 1);
yFit = polyval(linearCoefficients, s);
loglog(s, yFit, 'r-', 'LineWidth', 2)
  댓글 수: 1
Yazan
Yazan 2021년 8월 6일
편집: Yazan 2021년 8월 6일
You are not doing anything wrong, and the fitting is working. However, you are plotting the results using a base 10 logarithmic scale. See below the same result plotted using a linear scale.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2021년 8월 6일
Fit it to a power function:
LD = load('msd_help.mat');
m = LD.m;
s = LD.s;
fcn = @(b,x) x.^b(1).*exp(b(2));
B = fminsearch(@(b) norm(m - fcn(b,s)), rand(2,1))
yFit = fcn(B,s);
figure
loglog(s,m,'.')
hold on
plot(s, yFit,'-r')
hold off
grid
producing:
B =
0.867368600071621
-27.933653082691194
and:
.
  댓글 수: 6
Manny Kins
Manny Kins 2021년 8월 9일
Thanks for your help and insight
Star Strider
Star Strider 2021년 8월 9일
As always, my pleasure!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by