Student Support Forum: 'Nonlinear Fitting of User Defined Functions' topicStudent Support Forum > General > "Nonlinear Fitting of User Defined Functions"

 Next Comment > Help | Reply To Topic
 Author Comment/Response Kareem Zaghloul 08/07/00 2:35pm Hi, I was wondering if anyone has any ideas about how to use the NonlinearFit command to fit a user defined function to real data. Basically, I defined this function which takes a bunch of parameters and sets up a system of differential equations. It then solves these equations using NDSolve, does a couple more manipulations, and returns either a value or a list, depending on what I need to do. What I want to do is use NonlinearFit to fit the parameters of my model to a set of data. I figured I could just use the function I defined, and that NonlinearFit would iterate through the parameter space until the function returned a solution that minimized the error with the real data. But it looks like NDSolve won't work under these conditions, maybe because the equations it is using are defined by the parameters passed to it by NonlinearFit. Can anyone tell me if this approach is correct, and if not, what other suggestions there are out there. I've attached a bit of the code in addition to some of the error messages I was receiving so that maybe someone can maybe help me debug. Thanks, Kareem -------------------- This an example of the code I would like to run... --------------------- csize = {0.03, 0.06, 0.12, 0.25, 0.5, 1.0}; values = {0.2, 0.38, 0.7, 1.2, 2, 3}; data = Transpose[{csize, values}]; fn[c_, \[Sigma]_, A_] := Module[{foo, eqns, t, soln, ibc}, { eqns = {ibc[t] + Release[\[Sigma]] D[ibc[t], t] == Release[A] c, ibc[0] == 0}; soln = NDSolve[eqns, ibc, {t, 0, 3}, MaxSteps -> 10000]; foo = Table[N[ibc[t] /. soln], {t, 0, 3, 0.001}]; foo\[LeftDoubleBracket]100\[RightDoubleBracket] }]; NonlinearRegress[data, fn[c, \[Sigma], A]\[LeftDoubleBracket]1\[RightDoubleBracket], c, {{\[Sigma], 1}, {A, 1}}] -------------- And these are the error messages I am getting... -------------- NDSolve::''ndnum'': ''Encountered non-numerical value for a derivative at \ \!\(t\$52\) == \!\(6.3659873744`*^-314\).'' InterpolatingFunction::''dmval'': ''Input value \!\({0.001`}\) lies outside the \ range of data in the interpolating function. Extrapolation will be used.'' InterpolatingFunction::''dmval'': ''Input value \!\({0.002`}\) lies outside the \ range of data in the interpolating function. Extrapolation will be used.'' InterpolatingFunction::''dmval'': ''Input value \!\({0.003`}\) lies outside the \ range of data in the interpolating function. Extrapolation will be used.'' General::''stop'': ''Further output of \!\(InterpolatingFunction :: \''dmval\''\) \ will be suppressed during this calculation.'' NonlinearRegress::''nonnum'': ''The model is not numerical at \!\({\(\(\[Sigma] \ -> 1\)\), \(\(A -> 1\)\), \(\(c -> 0.03`\)\)}\). Check that all model \ parameters are included in the parameter list.'' NonlinearRegress[{{0.03, 0.2}, {0.06, 0.38}, {0.12, 0.7}, {0.25, 1.2}, {0.5, 2}, {1., 3}}, {0.}, c, {{\[Sigma], 1}, {A, 1}}] URL: ,

 Subject (listing for 'Nonlinear Fitting of User Defined Functions') Author Date Posted Nonlinear Fitting of User Defined Functions Kareem Zaghl... 08/07/00 2:35pm Re: Nonlinear Fitting of User Defined Functions Forum Modera... 08/14/00 9:11pm
 Next Comment > Help | Reply To Topic