lsqcurvefit claiming complex-valued function
Mostra commenti meno recenti
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.
Risposte (2)
Because the log of a negative real number is complex, e.g.,
log(-2)
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.
Categorie
Scopri di più su Pattern Recognition in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!