Simple lsqcurvefit does not work properly

Hello. I would like to do a simple lsqcurvefit. But it seems to be that I cannot write the code properly. The data is attached. For some background.
My code is:
n = 400; % number of partitions
l = 13; % length of Basilarmembran in cm
x = linspace(0.01, 13, n)'; % length of each partition 0.01 - 13 cm
b = 0.5; % width in cm at Helicotrema
t = 0.04; % height in cm
beff = b.*x/l; % length of each trapezium
dx = x(2:n) - x(1:n-1); % length of each mass oszillator
zs = dx.*(beff(1:n-1)+2.*beff(2:n))./(3*beff(1:n-1)+3.*beff(2:n)); % centroid of an trapezial-area
xeff = zs + x(1:n-1); % effectiv distance of each centroid
% ________BASIS The tip counts from x = 0.01 cm (basis) to x = 13 cm (apex)
% | .
% | /|\
% h| /_|_\
% | /__|__\ <-- This is one trapezium
% | / | \
% |___/____|____\
% |_________| APEX
filename = 'stifness.xls';
A = xlsread(filename);
xdata=A(:,1)/10; % x-values in cm
fdata=A(:,2); % y-values in Hz
s0 = [90, 1.7, 0.88]; % inital values, processed by hand
ub = [2e2, 2e0, 1e1]; % upper bound
lb = [1e1, 1e0, 1e-1]; % lower bound
options = optimset('TolFun',1.0e-15,'TolX',1.0e-15);
Gfun = @(s,x) s0(1).*(10.^(s0(2).*(13-x)/13)-s0(3));
fitfun = lsqcurvefit(Gfun,s0,xdata,fdata,lb,ub,options);
Gfuntest1 = s0(1).*(10.^(s0(2).*(13-xeff)/13)-s0(3)); % plot with inital values
Gfuntest2 = fitfun(1).*(10.^(fitfun(2).*(13-xeff)/13)-fitfun(3)); % plot with fitted values
semilogy(xeff, Gfuntest1,'g',xeff,Gfuntest2,'--k',xdata,fdata,'ob'); % plot data
Any suggestion for my little problem? I don't know, why the lsqcurvefit does not change the inital values. They are staying the same. It cannot be that I guessed perfect initial values.
Best regards
Henrik
EDIT: Sorry for the missed data. Now it is attached.

댓글 수: 4

John D'Errico
John D'Errico 2017년 10월 30일
We cannot run your code, since we lack the data. That means we cannot even test it out. And since we are not given any information as to the model, it is difficult to read your code. Yes, you made a picture, but not a terribly useful one.
Henrik Schädlich
Henrik Schädlich 2017년 10월 30일
편집: Henrik Schädlich 2017년 10월 30일
I thought the lsqcurvefit should work this time. That is why I did not try the other fitting procedure.
The data is attached properly now. Hopefully it is operating sufficiently now.
Henrik Schädlich
Henrik Schädlich 2017년 10월 30일
편집: Henrik Schädlich 2017년 10월 30일
Is it correct if I add:
Gfun = @(s,x) s(1).*(10.^(s(2).*(13-x)/13)-s(3));
fitfun = @(s) norm(fdata- Gfun (s,xdata));
options = optimoptions('ga', 'InitialPopulationMatrix',s0, 'MaxGenerations', 1E+5, 'FunctionTolerance',1E-8);
[a, fval, exitflag] = ga(fitfun, 3, [], [], [], [], [], [], [], options);
Is it ok to have seven times []?

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

답변 (1개)

Henrik Schädlich
Henrik Schädlich 2017년 11월 1일

0 개 추천

It's been a while but i found the problem.
Gfun = @(s,x) s(1).*(10.^(s(2).*(13-x)/13)-s(3));
Is the correct line.

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

질문:

2017년 10월 30일

답변:

2017년 11월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by