Re: HELP! Strange evaluations
- To: mathgroup at smc.vnet.net
- Subject: [mg33600] Re: HELP! Strange evaluations
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Wed, 3 Apr 2002 01:13:24 -0500 (EST)
- Organization: Universitaet Leipzig
- References: <a89174$p7h$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
it can't work, because your function has no derivatives ?
Or does it not work, because FindRoot[] can return complex values
for the the solution, and you can't minimize with a complex
valued function.
The minimization used by NonlinearRegress[] must evaluate the
derivative to know the direction in the parameter space.
You can try to find an approximate gradient
eqn = x /. Solve[Normal[Series[Cos[a x] - b x, {x, 0, 10}]] == 0, x] //
Simplify[#, a > 0 && b > 0] &;
grad = D[#, a] & /@ eqn;
(BestFitParameters /.
NonlinearRegress[data, goo[a, b], a, {b, {0.25, 1.}},
RegressionReport -> BestFitParameters, Gradient -> #] &) /@
grad
beside some error messages about a complex objective function
this works fine.
Regards
Jens
"Lawrence A. Walker Jr." wrote:
>
> Hi,
>
> For the life of me I can't figure out how to get the following to work
> correctly. I also tried using various combinations of Hold and Evaluate
> -- but to no avail.
>
> << Statistics`NonlinearFit`
>
> (* This works ok *)
> goo[a_, b_] :=
> FindRoot[( Cos[a x]) == b x, {x, 0}][[1, 2]];
>
> (* Here are some sample data *)
> data = Table[{i, goo[i, .5]}, {i, 0, 1, .2}];
>
> (* This doesn't work -- I expect b->.5 to be returned. *)
> BestFitParameters /.
> NonlinearRegress[data, goo[a, b], a, {b, {0., 1.}},
> RegressionReport -> BestFitParameters]
>
> After executing the above, I get the following error messages:
>
> FindRoot::frnum: Function {0. b+Cos[0. a]} is not a length 1 list of
> numbers at {x} = {0.}.
>
> NonlinearRegress::nonnum: The model is not numerical at {b->0., a->0.}.
> Check that all model parameters are included in the parameter list...
>
> How do I get the above to work.