Simple lsqcurvefit does not work properly
Show older comments
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 Comments
John D'Errico
on 30 Oct 2017
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.
Star Strider
on 30 Oct 2017
Henrik Schädlich
on 30 Oct 2017
Edited: Henrik Schädlich
on 30 Oct 2017
Henrik Schädlich
on 30 Oct 2017
Edited: Henrik Schädlich
on 30 Oct 2017
Answers (1)
Henrik Schädlich
on 1 Nov 2017
Categories
Find more on Nonlinear Optimization 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!