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

3 ビュー (過去 30 日間)
Gregory Manoukian
Gregory Manoukian 2023 年 7 月 17 日
回答済み: Lokesh 2024 年 7 月 25 日
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 2024 年 7 月 25 日
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 Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by