Complex values with nlinfit

3 次查看(过去 30 天)
Kai Hillers
Kai Hillers 2020-6-3
Hello everyone,
my code looks like this:
%initializing values
u_star = .2;
kappa = .4;
z_0 = 10^-6;
d = 0;
alpha = .11;
z = [33 40 50 60 70 80 90];
%sector means
m_smmr = [6.5261 6.6065 6.9178 6.9645 7.1122 7.3116 7.4411];
m_wntr = [10.5684 10.7004 11.2594 11.4037 11.6157 11.9577 12.1230];
%modelfunction
wpfun = @(a,z) (a(1) / kappa)*log((z-d)/a(2));
a = [u_star z_0];
wpsmmrfit = nlinfit(z,m_smmr,wpfun,a);
wpwntrfit = nlinfit(z,m_wntr,wpfun,a);
I expect real values for both fits, but the wpwntrfit is giving me a complex output. My outputs look like this:
wpsmmrfit =
0.3645 0.0269
wpwntrfit =
0.6349 - 0.0000i 0.0441 - 0.0000i
I have no idea why or whats going on. How do I make the wpwntrfit have non complex outputs?
Kind regards,
Kai
  2 个评论
Sulaymon Eshkabilov
If your chosen model logarithmic function is correct or what you need to use, then the data (Y) m_wntr need to be adjusted. By changing the values of m_wntr your fit model coefficients will be real. E.g.:
wpwntrfit = nlinfit(z,m_wntr-5,wpfun,a)
0.6349 1.0295
Or you'd need to change the model function type: wpfun
Kai Hillers
Kai Hillers 2020-6-3
Thank you for your answer!
Can you elaborate why the values of m_wntr are too big for the modelfunction? How would i have to change the modelfunction if I'm not changing the data.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by