0
$\begingroup$

I'm solving some differential equations by iterating and I want to use Chop to get rid of noice smaller than a certain threshold. However, I found that Chop only "chops" the real part, not the imaginary part. My question is, which function can I use in order to approximate both real and imaginary parts that are very close to zero by zero?

For example, if I try to do

A = 10^(-50);
B = I*10^(-50);
Chop[A + B]

The result is just that same number (and actually not even the real number is getting chopped so I'm not sure if I'm understanding this correctly). I would want the result to be zero.

$\endgroup$
  • $\begingroup$ I found that Chop only "chops" the real part are you sure about this? can you show a MWE showing this? Because I tried this a = 3; b = I* 3.000000000001; r = a + b; Chop[r] and it gives 3. + 3. I so it seems to work. This is using V12 $\endgroup$ – Nasser Oct 1 at 23:59
  • $\begingroup$ Threshold does this, but only on arrays: Threshold[{A + B}]. $\endgroup$ – Michael E2 Oct 2 at 1:15
8
$\begingroup$

I would want the result to be zero.

Exact numbers do not get Choped, because they are exact

A = 10^(-50);
B = I*10^(-50);
Chop[A + B]

Mathematica graphics

To get chop to work, The numbers need to be real and not exact as you have it. So just add a .

A = 10.^(-50);
B = I*10.^(-50);
Chop[A + B]

Mathematica graphics

Or apply N on it

Chop[N[A + B]]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.