Message Boards Message Boards


Fitting Complex-valued data with NonlinearModelFit.

Posted 10 years ago
2 Replies
5 Total Likes
One can do fits to complex data with FindFit by using a NormFunction for complex numbers.

However, NonlinearModelFit, doesn't appear to have a NormFunction option.  I'd like to have access to the extra functionality that FittedModel provides.

Does anyone know how I could get NonlinearModelFit to generalize the following FindFit example (this is a simple RC circuit impedance example):
fitModel = 1/(1/r + I c w);

noisyData = Table[{w, (fitModel + Random[Complex, {0, 0.1}] /. {r -> 2, c -> 1})}, {w, 0.01, 3, 0.05}]

FindFit[noisyData, fitmodel, {r, c}, w, NormFunction -> (Norm[Abs[#1^2]] &)]

Thanks, Craig
POSTED BY: W. Craig Carter
2 Replies
That's very clever. I wish I had thought of that,
Thanks, Craig
POSTED BY: W. Craig Carter
Posted 10 years ago
As long as you're fitting normed data, how about fitting it to a normed model?
Your model:
fitModel = 1/(1/r + I c w);
and your data:
noisyData =
  Table[{w, (fitModel + Random[Complex, {0, 0.1}] /. {r -> 2,
       c -> 1})}, {w, 0.01, 3, 0.05}];
I fit it as you did to get the rule:

fitRule =
FindFit[noisyData, fitModel, {r, c}, w,
  NormFunction -> (Norm[Abs[#1^2]] &)]
Now create a normed model:
fitModelconj = fitModel /. I -> -I;
normFitModel = Sqrt[Simplify[fitModelconj fitModel]]
and also norm the data:
normNoisyData = Map[Norm, noisyData, {2}];
Now fit the normed model to the normed data:
fittedModel =
  NonlinearModelFit[normNoisyData, normFitModel, {r, c}, {w}];
If you compare the output above to the normed model with the earlier fit, you see they don't quite agree, but almost:
normFitModel /. fitRule

Best regards,
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract