Re: An interesting problem




"umar " <umarkhan_80@xxxxxxxxxxx> wrote in message
news:gu8ibm$jb9$1@xxxxxxxxxxxxxxxxxxxxx
hi,
I tried the following code

i=0;
x=0;

for i=1:10
x=x+0.1
end
x-1


at the end x-1 should be zero, but it turns out to be -1.1102e-016 , WHY?

If you want exact values, use symbolic computation.

EDU>> clear all

syms x;
x=sym(0);
for i=1:10
x=x+sym(.1);
end

x=double(x);

x-1

0


--Nasser


.



Relevant Pages

  • Re: An interesting problem
    ... at the end x-1 should be zero, but it turns out to be -1.1102e-016, WHY? ... that go into more depth on floating-point computation: ... Steve Lord ...
    (comp.soft-sys.matlab)
  • Re: Solver refuses to find solution, though it exist
    ... This problem can be solved directly in Matlab using the "fzero" command. ... a plot of the function shows that there is a zero near 1.3. ...
    (comp.soft-sys.matlab)
  • Solver refuses to find solution, though it exist
    ... Zero is not a solution so I do not know why i get that, ... reaching pi there is a valid solution arround 1.3 which i do not get. ...
    (comp.soft-sys.matlab)
  • Re: Bug in solve.m (Symbolic)????
    ... syms x y z ... have denoted zero as a symbolic variable z, ...
    (comp.soft-sys.matlab)
  • Re: VHDL division
    ... time/timeTot is a duty cycle of a pwm signal and will always be less ... He says less than zero, so maybe negative time is his problem? ... Syms. ...
    (comp.lang.vhdl)

Loading