lsqcurvefit claiming complex-valued function

8 次查看(过去 30 天)
I have a function which I am fitting data to to extract parameters F(1), F(2), F(3), and F(4)
fun = @(F,frequency) ((1j*2*pi*frequency).^F(1)*10^F(2)+1./(10^F(3))).^(-1)+10^F(4);
fit_function= @(F,frequency) log(real(fun(F,frequency)));
When I try to run the function to fit the data:
[best_fit,resnorm(i,j,k,l)] = lsqcurvefit(fit_function,guess,frequency,log(Real),lower_bound,upper_bound,options);
I am receiving an error:
Error using lsqncommon (line 35)
Lower and upper bounds not supported with complex-valued initial function or Jacobian evaluation.
Although the fiting function fit_function is the log of a real valued part of the function, why is it considering that the function is complex? I removed the log to make sure it is not taking the log of negative values.

回答(2 个)

Matt J
Matt J 2024-2-12
Because the log of a negative real number is complex, e.g.,
log(-2)
ans = 0.6931 + 3.1416i

Torsten
Torsten 2024-2-12
移动:Torsten 2024-2-12
Although the fiting function fit_function is the log of a real valued part of the function, why is it considering that the function is complex?
Because the imaginary unit 1j is part of your function definition.
You should define your fitting function as
a*frequency^b + c
with a, b, c being constants to be fitted and constraint to be >=0.
The constants F(3) and F(4) cannot be estimated separately - they can only be used as one constant c > 0.

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by