lsqcurvefit initial values stays the same

조회 수: 2 (최근 30일)
kai chung
kai chung 2019년 9월 4일
댓글: Jasmine Boparai 2021년 9월 3일
Hi all, I am working on this non-linear square curvefit function, however, despite many attempts, the initial guessess were always chosen despite of given boundaries. Unbounded worked. But that isn't within the bounds. I really at my end of working on possible ideas. The data given as a total of 101 for each array.
EDIT: I have made some changes which is now bounded and using the default trust-region-reflective algorithm
T = readtable('skin3.csv','ReadVariableNames',true); %skin3 Measured data
x = T{:,1}; %freq
y = T{:,2}; %real
%Transpose
freq = x.';
e_real = y.';
%optimoptions(@lsqnonlin,'StepTolerance',1e-6);
options = optimset('MaxFunEvals',10000);
options=optimset(options,'MaxIter',10000);
guess = 40;
UB = guess + 10;
LB = guess - 10;
lb = [-20,LB,1,0,-0.1];
ub = [20,UB,40,1,0.1];
x0 = [0.9,guess,8.2,0.236,0.05];
x = lsqcurvefit(@flsq,x0,freq,e_real,lb,ub,options)
e_f = x(1);
e_del = x(2)*1e2;
tau1 = x(3)*1e-12;
alf1 = x(4);
sig = x(5);
yfit = real(flsq(x,freq));
%plot e_real against freq
plot(freq,e_real,'k.',freq,yfit,'b-')
legend('Data','Fitted exponential')
title('Data and Fitted Curve')
Function:
function y = flsq(x,freq)
x(3)=x(3)*1e-12;
y = x(1) + (x(2)-x(1))./(1 + ((1j*2*pi.*freq*x(3)).^(1-x(4))))+x(5)./(1j*2*pi*freq*8.854e-12);
end
As you can see the result remained the same while the curve is not even close:
Capture.PNG
  댓글 수: 2
Torsten
Torsten 2019년 9월 4일
I guess you get complex numbers for x(1),...,x(5) when simulating the unbounded case.
Upper and lower bounds on the parameters only make sense if they are real-valued.
Do you see the problem ?
Matt J
Matt J 2019년 9월 13일
Alex Sha's comment moved here:
Hi, chuen kai chung, would you please attach your data file please, either in Excel format or text format

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

채택된 답변

Alex Sha
Alex Sha 2019년 9월 13일
Have a look the results below, it is curve fitting of complex function:
Root of Mean Square Error (RMSE): 0.41174673299835
Sum of Squared Residual: 34.2461451712325
Correlation Coef. (R): 0.993473244156721
R-Square: 0.986989086855279
Adjusted R-Square: 0.98661284187563
Determination Coef. (DC): 0.984776903952251
F-Statistic: 6477.07873557149
Parameter Best Estimate
-------------------- -------------
x1 -11.6554338755058
x2 42.431711066831
x3 -4.55460615654172E-12
x4 0.295425568159937
x5 -0.527862954468673
t1.jpg
t2.jpg
  댓글 수: 1
Jasmine Boparai
Jasmine Boparai 2021년 9월 3일
Hi Alex, can you help me in doing the same thing for my data

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by