After some long calculations, Mathematica gives me this output:

$-0.11728 \, G_1^{\phantom{1}2} - 0.0692416\, G_1\, G_2 - 0.000011728 G_2^{\phantom{2}2}$

where G1 and G2 are two coefficients whose value I don't know, but I know that it must be integers and in the range (0; 10) (extremes excluded).

The last term is much smaller than the other two: how can I get rid of it? Chop doesn't work here since it only deals with numerical expressions.

  • 2
    $\begingroup$ Try Chop[expr, 1.*^-4]. $\endgroup$ – J. M.'s technical difficulties Oct 10 '16 at 13:34
  • 1
    $\begingroup$ Note that the last term can be the major term in the range given, e.g., if G1 = 0.001, G2 = 9. $\endgroup$ – Michael E2 Oct 10 '16 at 15:19
  • $\begingroup$ Sorry, you are right, but I forgot to write that the coefficients must be integers. $\endgroup$ – mattiav27 Oct 10 '16 at 15:29
  • $\begingroup$ No. As I have written, extremes are excluded. $\endgroup$ – mattiav27 Oct 11 '16 at 7:32
  • $\begingroup$ Oh gosh. Somehow I read it several times as "included." Not sure how that happened. Sorry for that. (You should use @Michael E2 to make sure I'm notified.) $\endgroup$ – Michael E2 Oct 11 '16 at 22:42

If you want to apply Chop to just the numerical expressions you can use a Rule with a Condition that the subject is a number:

delta = 0.01;
rule = x_ :> Chop[x, delta] /; NumericQ[x]

exp = -1.2 G1^2 - 0.02 G1 G2 - 0.000011 G2^2;

exp /. rule

-1.2 G1^2 - 0.02 G1 G2

|improve this answer|||||

Chop accepts a second argument and appears to work only on numerical parts of an expression:

expr = -0.11728 G1^2 - 0.0692416 G1 G2 - 0.000011728 G2^2;

Chop[expr, 10^-3]

-0.11728 G1^2 - 0.0692416 G1 G2

|improve this answer|||||
  • $\begingroup$ +1. You could even quote the docs to support your edit: "Chop[expr] replaces approximate real numbers in expr that are close to zero by the exact integer 0." $\endgroup$ – Michael E2 Oct 11 '16 at 23:03

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.