chop missing

David Bateman David.Bateman at motorola.com
Wed Apr 16 04:02:35 CDT 2008


HoX wrote:
> David Bateman ha scritto:
>> HoX wrote:
>>  
>>> I find out that the matlab's command /chop/ is missing in octave. I
>>> write a simple function which implements it in a really simple way
>>> and I hope you will like it.
>>>
>>>     function [y] = chop ( x , t )
>>>         y = x - mod ( x * 10^(t-1), 1 ) * 10^( -(t-1) );
>>>
>>>       
>> The only references I can find to the chop function are in the original
>> version of Matlab (ie the one written in fortran with no m-files) and in
>> Nick Higham matrix toolbox at
>>
>> http://www.maths.manchester.ac.uk/~higham/mctoolbox/
>>
>> Which are you referring to.. If its Nick's his toolbox is licensed under
>> the GPL and there is tehrefore no need to rewrite this function.
>>
>> D.
>>
>>   
> I'm referring to the matlab's one. In the end of this page [1] there
> is a reference to it.
> An example of /chop/ is:
>    chop ( pi , 3 ) = 3,140000000
> I don't know if there is another way to do that, neither I know if the
> Nick Higham version does the same thing.
>
>
> [1] http://ccrma.stanford.edu/~jos/pasp/Matlab_Octave_Programs.html
>

% matlabR2007b -nojvm -nosplash
                              < M A T L A B >
                  Copyright 1984-2007 The MathWorks, Inc.
                         Version 7.5.0.338 (R2007b)
                               August 9, 2007

 
  To get started, type one of these: helpwin, helpdesk, or demo.
  For product information, visit www.mathworks.com.
 
>> help chop

chop not found.

Use the Help browser Search tab to search the documentation, or
type "help help" for help command options, such as help for methods.

Seems pretty conclusive to me that is is not in Matlab 2007b and in fact
later releases.. It appears that this function was in Matlab 4 but was
cut in Matlab 5 and was in the control toolbox and not the Matlab core.
In current versions of the the control toolbox (at least up to version
2007a) it is in the control/ctrlobselete subdirectory and has been for
many years, and so the use of this function must be discouraged. Looking
around the help string for chop is

<quote>
    CHOP CHOP(X,n) rounds the elements of X to n significant
    figures.

    e.g. chop(3.141592,5) returns 3.141600000..

    CHOP(X,n,unit) rounds the elements of X to n significant
    figures whose digits (mantissa) are exactly divisible
    by unit.

    e.g. chop(3.141592,3,5) returns 3.150000000..
    chop(3.141592,3,3) returns 3.150000000..
    chop(3.141592,3,2) returns 3.140000000..
</quote>

and I found a sample implementation at

http://www.liv.ac.uk/pjgiblin/maths/mfiles/chop.m
http://perso-math.univ-mlv.fr/users/newton/TPetTD/TP1.pdf

though both implementation are missing the third argument. If you have
to use this function then use one of these.

D.



-- 
David Bateman                                David.Bateman at motorola.com
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



More information about the Bug-octave mailing list