Thanks for your help (and to all those above)!
The reason I want to do this is that I perfrom an optimization seeded with a state vector with variables measured in radians. The objective function is horrible, in that there is a large number of points in the state space where the objective function's 1st derivative is unavailable. As such rounding errors can effect which "side" of the 1st order discontinuity the estimate is on. So when I return the converged state in degrees (for interpretability), but then reevaluate the objective function (say to try and break convergence using a different optimizer), the "cost" doesn't match the convergence value. So my plan is to map any potential state update to another point where the inversion works perfectly.
In hindsight I should have written the program so the conversion only happens right before I plot something.
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gmvctd$efv$1@fred.mathworks.com>...
> "Andrew" <awbsmith@itee.uq.edu.au> wrote in message <gmtro9$oqm$1@fred.mathworks.com>...
> > .....
> > What I would like to do, is define a set of real numbers X where the conversion from radians to degrees can be inverted exactly, so
> >
> > (x * (180/pi)) * (pi/180) = x for all x in X
> >
> > then whenever I get a value in radians I can map it to its closest value in X and problem solved. But I don't know how to do that.
> > ......
>
> If you look for equality in x==(x*(180/pi))*(pi/180) for randomly selected values of x, you will probably find that it holds exactly for about 85% of all such selections using matlab's double precision numbers. Therefore, there is no possibility of storing these numbers in a table. However, it does mean that for any given value of y, you wouldn't ordinarily have to look very far from y before encountering an x that does satisfy this equality. You could find it with this procedure or something similar:
>
> a = 180/pi; b = pi/180;
> k1 = 1+1/2^52;
> k2 = k1;
> x = y;
> while x~=(x*a)*b
> x = k2*y;
> k1 = 1/k1;
> k2 = k1/k2;
> end
>
> This should almost always give you an x very quickly with the required property in the immediate vicinity of y. (However, reducing the number of "significant figures" in x will not be of any help.)
>
> However, I find it curious that you should want to do a thing like this. Roundoff errors of this kind are a fact of life for anyone doing numerical calculations, whether in binary or in decimal, and whether using a computer or a handheld calculator. I would think that the very small errors produced by doing the radians > degrees > radians conversions would be quite acceptable in any reasonable computing environment.
>
> Roger Stafford
