Curve Fitting complex data (x,y) for constant extraction.
3 views (last 30 days)
Show older comments
Hello,
I've been following the following link -- https://www.mathworks.com/help/optim/ug/fit-model-to-complex-data.html#
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)
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 Comments
Image Analyst
on 17 Jul 2023
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.
Answers (1)
Lokesh
on 25 Jul 2024
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)))
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!