Fit experimental results to an equation and get fit parameters

6 次查看(过去 30 天)
Hi,
I have the following code, which I try to fit some results to an equation and evaluate the parameters, but the fit didn't match at all. I tried also to change p0 values, but no fit occurs.
any help?
% x-axis
Freq = [0.44959;0.52452;0.59945;0.67439;0.74932;0.82425;0.89918;0.97411;1.04905;1.12398;1.19891...
;1.27384;1.34877;1.4237;1.49864;1.57357;1.6485;1.72343;1.79836;1.8733;1.94823;2.02316];
% y-axis
Re_Before = [397317000;313600000;245333000;189330000;145070000;112878000;92863500;84352900;85755700....
;94968300;110273000;131418000;160374000;201494000;261214000;347602000;469832000;637160000;856592000;1128290000;1438380000;1751530000];
% Pre_Defined
elect = 1.6e-19;
e_mass = 9.11e-31;
effective_mass = 3.8*e_mass;
epsilon = 8.85e-12;
C = -1;
%% Fitting:
fun = @(p,Freq) real(((epsilon*p(1)^2)./(p(2)-1i.*Freq)).*(1+((C*p(2))./(p(2)-1i.*Freq))));
p0 = [1e27,1e7];
p = lsqcurvefit(fun,p0,Freq,Re_Before);
%% calculate Density and output needed values
Plasma_Freq_Squared = p(:,1);
Electron_Density = epsilon*Plasma_Freq_Squared*effective_mass/elect^2
Gamma = p(:,2)
effective_mass
C
times = linspace(Freq(1),Freq(end));
plot(Freq,Re_Before,'ko',times,fun(p,times),'b-')
legend('Data','Fitted exponential')
title('Data and Fitted Curve')
ylabel('Real Conductivity (S/m)')
xlabel('Frequency (THz)')
grid on
  1 个评论
Matt J
Matt J 2020-8-25
We can't help much because we have no way to be sure that you are using an appropriate model equation. At the very least, however, I think you should change units on the y-axis so the order of magnitude is not 1e18.

请先登录,再进行评论。

回答(1 个)

Ayush Gupta
Ayush Gupta 2020-9-2
The fit function in MATLAB can be used to fit a data and the type of fitting can be specified by fittype argument in the function. Refer to the following code for fitting the data and plotting in on the map:
fit(Freq,Re_Before,'smoothingspline')
plot(ans,Freq,Re_Before)
For examples on how to use fit function and its documentation click here.

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by