help-octave
[Top][All Lists]
Advanced

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

Puncher soft limiter !!!


From: cctsim
Subject: Puncher soft limiter !!!
Date: Wed, 4 Jun 2003 01:57:10 +0100 (BST)

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 = 5  
>>max(puncher([0:0.1:5],5))
ans = 5  

which are ok, but
>>max(puncher([-5:0.1:5],5))
ans = 4.9000 
which is wrong !!

If I change the sampling interval, I get
>>max(puncher([-5:0.01:5],5))
ans = 5
>>max(puncher([-5:0.001:5],5))
ans = 5
>>max(puncher([-5:0.0001:5],5))
ans = 4.9999

I also noticed that only the upper limit causes the problem.
Can anybody check what is wrong in the code ? 

I use octave 2.1.49 compiled using gcc-3.2.3
on redhat 7.1 with

./configure --prefix=/opt/octave/2.1.49 \
        --with-g77 \
        --enable-dl \
        --enable-shared \
        --enable-lite-kernel \
        --enable-picky-flags \
        --enable-rpath 

The code of the c++ function is:

#include <octave/oct.h>
DEFUN_DLD (puncher, args, ,
 "-*- texinfo -*-\n\
@deftypefn {Loadable Function} address@hidden  = } puncher (@var{x}, @var{A})\n\
Puncher soft limiter @var{x}.\n\
@end deftypefn")
{
octave_value retval;
int i, j;

int nargin = args.length();

double A (args(1).double_value());

int nr (args(0).rows());
int nc (args(0).columns());
Matrix y(nr,nc);

Matrix x (args(0).matrix_value());

for (i=0;i<nr;i++){
  for (j=0;j<nc;j++){
    if ((x(i,j)>=-A)&&(x(i,j)<=A))
      y(i,j)=x(i,j);
    else
      y(i,j)=0;
  } 
}
retval=y;
return retval;
}


Thanks in advance
cctsim



__________________________________________________
Yahoo! Plus - For a better Internet experience
http://uk.promotions.yahoo.com/yplus/yoffer.html



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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