필터 지우기
필터 지우기

Curve Fitting complex data (x,y) for constant extraction.

조회 수: 11 (최근 30일)
Gregory Manoukian
Gregory Manoukian 2023년 7월 17일
답변: Lokesh 대략 10시간 전
Hello,
to try and extract the real constants (N_s,Tau_s, and c) from the Drude-Smith derivation for complex conductivity. This involves fitting both the real and imaginary components (which may be the problem in itself, since the example fits regular data with complex noise?)
I've attempted both lsqnonlin and lsqcurve fit methods.
file =['DSfit_Sitest.xls']; %%file attached
input = xlsread(file);
x = input(:,1); %%%% xdata, freqency, omega, real numbers from (0.2-1.4 THz)
R = input(:,2); %%%% Real component (blue in plot)
I = input(:,3);%%%% Imaginary component (orange in plot)
ydata = complex(R,I); %%%% complex conductivity, sigma_s
q = 1.602E-19; %% charge
m = 0.98; %% effective electron mass
mi = 1/0.98; %% inverse electron mass used to make typing the equation simpler
objfcn = @(C)(((C(1)*(q^2)*mi*C(2))./(1-1i.*x.*C(2))).*(1+(C(3)./(1-1i.*x.*C(2))))) - ydata;
opts = optimoptions(@lsqnonlin,'Display','off');
x0=[1e17, 100, -0.1]; %% initial guesses, I expect these to be reasonable values
LB = [1e15, 1, -1]; %%Typical carrier concentrations (cm-3), Tau_s (C(2)) units in picoseconds, -1<c<0
UB = [1e21, 1000, 0];
[const,~,residual,exitflag,output] = lsqnonlin(objfcn,x0,[],[],opts); %% does not run with LB and UB, so i leave blank.
This method outputs the initial guesses, and when I use the initial guesses to plot the outputs I get my data graph flipped, meaning my function just equals zero.
Using lsqcurvefit
objfcn = @(C,x)(((C(1)*(q^2).*mi.*C(2))./(1-1i.*x.*C(2))).*(1+(C(3)./(1-1i.*x.*C(2)))));
opts = optimoptions(@lsqcurvefit,opts);
x0=[1e17, 100, -0.1];
LB = [1e15, 1, -1];
UB = [1e21, 1e3, 0];
[constan,resnorm] = lsqcurvefit(objfcn,x0,x,ydata,[],[],opts)
constan = 1×3
1.0e+17 * 1.0000 0.0000 -0.0000
resnorm = 2.5565e+06
I get the error "not enough input arguments" in my objfcn, and it still outputs the initial guesses
Any help with why this isnt working or if im doing something really wrong is greatly appreciated! I am a novice Matlab user.
Thank you!!
  댓글 수: 2
Image Analyst
Image Analyst 2023년 7월 17일
Evidently it doesn't give that error when run here in MATLAB Answers. Attach ALL the red text so we can see which line of code is throwing the error.
Gregory Manoukian
Gregory Manoukian 2023년 7월 17일
편집: Gregory Manoukian 2023년 7월 17일
"
Not enough input arguments
objfcn = @(C,x)(((C(1)*(q^2)*mi*C(2))./(1-1i.*x.*C(2))).*(1+(C(3)./(1-1i.*x.*C(2)))));
"
Sorry, I had put a cleaned up version of the code in my question, please note 'freqfit' = x for plots, i renamed it for simplicity of entering the function. Is it possible that the r2023 has changed so that the error doesnt appear? Thank you, please let me know if I can give any more information.

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

답변 (1개)

Lokesh
Lokesh 대략 10시간 전
Hi Gregory,
From the code attached in the comment, it seems that the error "not enough input arguments" arises due to the following line of code:
plot(freqfit, real(objfcn(constan)))
hold on
plot(freqfit, imag(objfcn(constan)))
Here, 'objfcn' is expecting two arguments, but only one argument 'constan' is being passed. If you intend to pass a second argument, which i assume to be 'x', the corrected code should be:
plot(freqfit, real(objfcn(constan,x)))
hold on
plot(freqfit, imag(objfcn(constan,x)))

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by