Re: FindFit and complex data
- To: mathgroup at smc.vnet.net
- Subject: [mg99318] Re: FindFit and complex data
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Sat, 2 May 2009 06:02:18 -0400 (EDT)
On 5/1/09 at 5:25 AM, paul.ellsmore at nanion.co.uk (Paul Ellsmore) wrote: >I'm having trouble with FindFit, when I try to fit complex data. =46indFit is really not designed to handle complex values. It can be made to do so but not easily. >Take this function: >explicitz = >R1 + R2*(I/(-2*pi*fr*C2)/(R2 + I/(-2*pi*fr*C2))) + >R3*(I/(-2*pi*fr*C3)/(R3 + I/(-2*pi*fr*C3))) I assume when you actually did this and used the model below you actually typed Pi not pi as above. With a lower case p this would be a new undefined symbol and definitely cause problems. <snip> >The fit values are not very good at all, so I try to add >constraints, such as fitR1>0, but this makes it MUCH worse: <snip> >So why is this? Can someone give me some hints as to how constraints >affect the way FindFit searches for results? I don't have a good understanding of how constraints are used in =46indFit. But, the issues with non-linear fitting are generally best resolved by specifying good starting values. While you did indicate the values of capacitance and resistance you used, you did not say how you generated your sample data. If I avoid the issue of complex values by taking the absolute value and provide good starting values I can get good results. That is: In[65]:= freqs = Outer[#1 10^#2 &, {2, 4, 8} // N, {-1, 1, 2}]; explicitzdata = Transpose@{Flatten[freqs], Abs[explicitz /. fr -> Flatten[freqs]]}; In[67]:= parameters = {fitR1, fitR2, fitR3, fitC2, fitC3}; start = {1000, 1000, 1000, 10^-5, 10^-7} // N Out[68]= {1000.,1000.,1000.,0.00001,1.*10^-7} In[69]:= FindFit[explicitzdata, Abs@model, Transpose@{parameters, start}, fr] Out[69]= {fitR1->1000.,fitR2->3000.,fitR3->2000.,fitC2->9.4*10^-6,fitC3->= 9.4*10^-8} Doing non-linear fitting is inherently difficult. For many problems it is very difficult to avoid getting trapped by a local minimum resulting in a less than optimal solution. Using Method->NMinimize with FindFit might help. Or it might be better to use NMinimize directly so as to have more control over the search algorithm used to find the desired parameters.