Complex values with nlinfit

3 views (last 30 days)
Kai Hillers
Kai Hillers on 3 Jun 2020
Commented: Kai Hillers on 3 Jun 2020
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 Comments
Sulaymon Eshkabilov
Sulaymon Eshkabilov on 3 Jun 2020
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 on 3 Jun 2020
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.

Sign in to comment.

Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!