MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: tiny negative numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92867] Re: tiny negative numbers
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Thu, 16 Oct 2008 05:04:37 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <gd4dsk$bkv$1@smc.vnet.net>

a wrote:

> I am trying to solve a set of differential equations using NDSolve.
> But I'm seeing some really tiny negative numbers like this one:
> -1.28E-12. I'm guessing this is a machine-precision related problem.
> So I was wondering if I can somehow ensure that the variable values
> never go below 0, or alternatively, ensure that these tiny numbers
> equate to 0?

Use the command *Chop*. See

http://reference.wolfram.com/mathematica/ref/Chop.html

 From the online help:

   . Chop[expr] replaces approximate real numbers in expr
     that are close to zero by the exact integer 0.

   . Chop[expr,delta] replaces numbers smaller in absolute
     magnitude than delta by 0.

   . Chop uses a default tolerance of 10^-10.

   . Chop works on both Real and Complex numbers.

   In[1]:= Exp[N[Range[4] Pi I]]

   Out[1]= {-1. + 1.22461*10^-16 I,
     1.- 2.44921*10^-16 I, -1. + 3.67382*10^-16 I, 1.- 4.89843*10^-16 I}

   In[2]:= Chop[%]

   Out[2]= {-1., 1., -1., 1.}

Regards,
-- Jean-Marc


  • Prev by Date: Re: parameters problem in FindFit
  • Next by Date: Re: Newbie question: equations with sums.
  • Previous by thread: Re: tiny negative numbers
  • Next by thread: Radon and fan beam projection (forward and backward)