Re: How to do a Nonlinear Complex Fit ?
- To: mathgroup at smc.vnet.net
- Subject: [mg22443] Re: [mg22411] How to do a Nonlinear Complex Fit ?
- From: "Mark Harder" <harderm at ucs.orst.edu>
- Date: Wed, 8 Mar 2000 02:21:44 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Ronald, Unfortunately, NonlinearRegress (& NonlinearFit) don't take observations of the form {x,f(x),g(x) }, but you can arrange your f(x) and g(x) values in one list, f(x) first, followed by g(x). In this case NonlinearRegress will supply indices (1. through (Length[f(x)]+Length[g(x)]) ) one at a time to your model function, which should be written to generate the proper x, f(x), and g(x) values in order. I hope the example I worked out will make this clear: <<Statistics` (* x-values & the real and imaginary parts *) xdat= N[Table[x,{x,0.,Pi,Pi/10} ] ] rePart=3. Cos[1.1 xdat]; imPart=3. Sin[1.1 xdat]; (* the data vector *) ydata=Flatten[Append[rePart,imPart ] ]; (* the model function for the real parts, followed by the imaginary parts *) ClearAll[model]; model[x_List,i_,limit_Integer,a_,b_]:= If[ i<= limit,a Cos[b x[[i]] ], a Sin[b x[[i-limit]] ] ]; (* set the limit dividing real from imaginary parts in the list, and fit *) limit=Length[xdat]; NonlinearRegress[ydata,Evaluate[model[xdat,i,limit,a,b] ],i,{a,b}] Important note: although i is an index, Mathematica will substitute real values for i; you must allow model to accept non-integer i-values. I didn't add any noise to the data, and the regression returned exactly 3. and 1.1 for a & b. -mark harder -----Original Message----- From: Ronald Sastrawan <sastra at fmf.uni-freiburg.de> To: mathgroup at smc.vnet.net Subject: [mg22443] Re: [mg22411] How to do a Nonlinear Complex Fit ? >Hello Mark, > >thanks for your answer ! >My data is real. I measure the real and the imaginary part in dependance of x >(in my case the frequency, I am doing impedance measurements). So my data looks >like (x, f(x), g(x)), where f and g are the imaginary and complex part >respectively, but all of it is real. My model yields expressions for both f(x, >k1,k2,k3,k4,k5) and g(x,k1,k2,k3,k4,k5), where the k are the fit parameters >(they should be the same for both f and g). > >Thanks for your effort, > >Ronald > >Mark Harder schrieb: > >> In mg22411 you wrote >> "I am trying to fit a complex function to real data. The data consists of >> real and imaginary part." >> >> Before I think about this, I need to know more. Is the data a vector of >> complex numbers (with "real & imaginary part" or real? In the former case, >> I think you will have to create a data vector with real and complex parts >> separated, and real and complex parts of the model function separated in the >> same way -- Mathematica's NonlinearFit[] won't accept multi-valued data, >> and I think it sees complex numbers as 2D vectors over the reals (not >> certain, that's what I need to play with). >> >> Any questions or clarification, just e-mail me. I didn't submit this note >> to the whole group. >> mark harder >> harderm at ucs.orst.edu > >-- >Ronald Sastrawan > >Freiburg Materials Research Center >Stefan-Meier-Str. 21 >D-79104 Freiburg >Germany >Tel: ++49/761/203-4802 >FAX: ++49/761/203-4801 >EMAIL: sastra at fmf.uni-freiburg.de >http://www.fmf.uni-freiburg.de/~biomed/FSZ/forschung-FSZ.html > >