|
From: | Lorenzo Fiorentini |
Subject: | Re: Puncher soft limiter !!! |
Date: | Wed, 04 Jun 2003 13:24:48 +0200 |
User-agent: | Opera7.11/Win32 M2 build 2880 |
Not always the last element of your vector [a:(b-a)/n:b] is b. Sometimes it is b-(b-a)/n, because of rounding done n times when adding (b-a)/n. NB. If the step is not a power of two [2^(-k)], there must be some rounding on a binary machine.
Try adding eps or 2*eps or step/10 to b, or use a different sintax like (a+[0:n]*(b-a)/n).
I am (pretty ;) sure it will work. Lorenzo On Wed, 4 Jun 2003 01:57:10 +0100 (BST), cctsim <address@hidden> wrote:
Hi all, I have written the c++ code below to implement a puncher funtion for a soft limiter. By definition, that is f(x)=x for -A<=x<=A and f(x)=0 otherwise I thought it was working fine until I noticed the following problem:max(puncher(5,5))ans = 5max(puncher([0:0.1:5],5))ans = 5 which are ok, butmax(puncher([-5:0.1:5],5))ans = 4.9000 which is wrong !!
-- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------
[Prev in Thread] | Current Thread | [Next in Thread] |