Simple lsqcurvefit does not work properly

2 ビュー (過去 30 日間)
Henrik Schädlich
Henrik Schädlich 2017 年 10 月 30 日
回答済み: Henrik Schädlich 2017 年 11 月 1 日
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 件のコメント
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 日
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.

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by