3

I'm struggling how to get rid of expressions that are trivially zero in Mathematica from the output. 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 

the 0*(1-p1) is obviously zero, but I couldnt find a way to get rid of it ? (I'm relatively new to Mathematica...) Simplify didnt work, N[ ] didnt work FullSimplyfy[ ] as well.

Any advice ? Because in a big expression using this interpolation, these zero-expressions accumulate... and i have 10 line answer instead of a constant.

Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
Vytautas
  • 177
  • 1
  • 8
  • 1
    @Vyautas I see you have a good response already. I'll mention that as an alternative you might try collecting those zeros and sending them to some country that has a shortage of them. Costs next to nothing to send--zeros are quite light (some say they are massless, but I'm not convinced). – Daniel Lichtblau Feb 25 '11 at 03:37

1 Answers1

4

I think the function you require is Chop.

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

For example:

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

both give as output:

p1

681234
  • 4,214
  • 2
  • 35
  • 42