Borrar filtros
Borrar filtros

lsqcurvefit claiming complex-valued function

3 visualizaciones (últimos 30 días)
Abbas53
Abbas53 el 12 de Feb. de 2024
Movida: Torsten el 12 de Feb. de 2024
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.

Respuestas (2)

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

Torsten
Torsten el 12 de Feb. de 2024
Movida: Torsten el 12 de Feb. de 2024
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.

Categorías

Más información sobre Systems of Nonlinear Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by