"John D'Errico" <woodchips@rochester.rr.com> wrote in message <hmr07i$l98$1@fred.mathworks.com>...
> "Jeff " <spREMOVEHITSjeffAT@SIGNoptonline.net> wrote in message <hmqk55$f1c$1@fred.mathworks.com>...
> > Can someone please explain why the last statement is returning 0 when the two statements seem equal to me.
> >
> > EDU>> k=3;
> > EDU>> (9*2^k  8*3^k)/6^k
> > ans =
> > 0.666666666666667
> > EDU>> u(k+1)
> > ans =
> > 0.666666666666667
> > EDU>> (9*2^k  8*3^k)/6^k == u(k+1)
> > ans =
> > 0
> >
> > The formula on the second line is the closed formula for u_k I obtained using a generating function on the following sequence:
> > u(0)=1
> > u(1)=1
> > 6u(k)=5u(k1)u(k2)
> >
> > I realize that way out in the sequence, there's bound to be some rounding error, but we're talking about the fourth term here. Why does Matlab say they're not equal?
> >
> > Thanks,
> > J
>
> What you misunderstand is that rounding error happens
> after EVERY floating point addition, subtraction, etc.
>
> The least significant bits of these numbers are not
> identical, so they will not be equal.
>
> John
OK. Thanks all. That makes sense now.
How can I write this type of code correctly? Do I just multiply both by 10^n, round, and compare?
