help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to print this function?


From: Max Brister
Subject: Re: How to print this function?
Date: Tue, 22 May 2012 14:50:58 -0600

On Tue, May 22, 2012 at 2:27 PM, Przemek Klosowski
<address@hidden> wrote:
> On 05/22/2012 03:27 PM, marco atzeri wrote:
>>
>> On 5/22/2012 8:26 PM, Sergei Steshenko wrote:
>>>
>>>
>>>
>>> Though not related to your original question, 0.1 may be a periodic
>>> fraction in your _binary_ CPU, so you better write
>>>
>>>
>>> t = 0.1 * [-10:1:10];
>>>
>>
>> irrilevant in this case
>>
>> octave:4>  [-1:0.1:1;]-0.1*[-10:1:10;]<eps
>
> <... shows that the differences are all less than eps ...>
>
> Well, the point of 'eps' is that it is the smallest normalized number so it
> masks the simple roundoff errors. In this case you haven't accumulated
> enough of roundoff to exceed eps, but if you keep going you eventually will.
> A quick try shows that you need four orders of magnitude more operations:
>
> min([-1:0.00001:1;]-0.00001*[-100000:1:100000;]<eps)

Actually, [-100000:1:100000;] is fine. Look at the code here
http://hg.savannah.gnu.org/hgweb/octave/file/d95e719ef108/liboctave/Range.cc#l59

Octave's algorithm for getting a matrix from a range works as folows
1) Determine the number of elements in a range
2) Compute each index of the matrix using the equation: result(i) =
base + i * increment; where i is integer and goes from 0 to the number
of elements.

So there will be some difference between [-1:0.00001:1;]-0.00001 and
[-100000:1:100000;] due to floating point roundoff errors. However,
this difference does not accumulate. If we look at

[a,b] = max(abs([-1:0.00001:1;]-0.00001*[-100000:1:100000;]))

We see that the greatest error occurs at the 150001 element out of
200001 elements total. If the error was accumulating, we would expect
for the largest difference to occur closer to the end. Furthermore, if
there was actually an accuracy issue we would expect to see a
different number of columns in each matrix.

> Sergei showed you the correct form that will never fail.

Sergi's form is simply a more awkward way of writing code.

Max Brister


reply via email to

[Prev in Thread] Current Thread [Next in Thread]