[Top][All Lists]

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

ans = 5  
ans = 5  

which are ok, but
ans = 4.9000 
which is wrong !!

If I change the sampling interval, I get
ans = 5
ans = 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 \

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))
return retval;

Thanks in advance

Yahoo! Plus - For a better Internet experience

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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