Math, the remaining zeros

I am afraid of how to get rid of expressions that are trivially zero in Mathematica from the result. Example:

    pVec = Table[{i, Exp[-i*0.03]}, {i, 0, 2.5, 1/2}]; 

    pVec[[2, 2]] = p1; 
    pVec[[3, 2]] = p2; 
    pVec[[4, 2]] = p3; 
    pVec[[5, 2]] = p4; 
    pVec[[6, 2]] = p5; 

    qq = Interpolation[pVec, InterpolationOrder -> 1]; 

>> qq[0.5] 
>> 0. (1 - p1) + p1 

0*(1-p1)obviously equal to zero, but I could not find a way to get rid of it? (I'm relatively new to Mathematica ...) Simplification did not work, N[ ]did not work FullSimplyfy[ ], as well.

Any tips? Since in a large expression using this interpolation, these null expressions accumulate ... and I have a 10-line answer instead of a constant.

+3
source share
1 answer

I think you need a function Chop.

From the reference: " Chop[expr]replaces the approximate real numbers in the expression that are close to zero with the exact integer 0"

For instance:

Chop@qq[0.5]
Chop[0.` (1 - p1) + p1]

both give as output:

p1

+4
source

Source: https://habr.com/ru/post/1794495/


All Articles