Uniroot() finds "a" solution in an interval, not necessarily "the" solution
that you want. There may be multiple roots, some of which meet your
constraints. Since you've got R or S-plus which have great graphical tools,
I would suggest that you plot y, c, d, and the residual (which I called
"resid") over various ranges of x, and get some insight into how your
function behaves, and where the roots are (the zero-crossings of resid).
Then you will be able to tell if there are roots in a region of x that
satisfies any constraints you might want to add. You can then find the root
that lies in the correct interval by changing the interval searched by
uniroot(). I hard-coded this interval as c(-9999.0,9999.0). (Violating my
own rule against hard-coding constants!)
I don't know where these equations have arisen from, but sometimes plotting
a function can give you more insight into the problem you're trying to solve
than you would get by root-finding alone.
Alan
|