2
$\begingroup$

In my current macro, I have:

DeleteCases[Chop[FullSimplify[RowReduce[something]]], {0 ..}] 

This works fine for both, exact and numeric complex numbers (with modules of the order of 1 at most) in my "something".

However, the returned result is "Chop-ped", of course.

I would like to get the full precision (for all elements) also in numeric cases.
I tried to use:

DeleteCases[RowReduce[something], {x_..}/;PossibleZeroQ[Chop[FullSimplify[x]]]] 

This works fine as long as long as all "x" (in a "row") are exactly equal.
So, e.g. it does remove {1.*^-11, 1.*^-11} but unfortunately it does not remove {0, 1*.^-11} nor {1.*^-11, 0}.

Could you, please, help me with it.

Update (2019.08.05): Thank you very much for all your neat examples. I decided to use (I hope it really does what I "intend" it to do):

DeleteCases[FullSimplify[RowReduce[FullSimplify[something], ZeroTest->(PossibleZeroQ[Chop[FullSimplify[#]]]&)]], {__?(PossibleZeroQ[Chop[FullSimplify[#]]]&)}] 

Solutions based on Pick have two problems for me. First, they completely remove "rows" with empty lists (i.e. {}). Second, the very first step is Chop, which unconditionally evaluates all elements of all "rows" while, in the solution based on DeleteCases, the {__?(TrueOrFalse[#]&)} pattern will evaluate elements of each "row" only until the first one that returns "False" (at least that's how I imagine it works). Also, the solution which uses Total would need an additional Abs inside, otherwise it completely removes "rows" which elements sum up to 0 (e.g. {-1, 1}).

$\endgroup$
0

2 Answers 2

2
$\begingroup$

I would recommend this type of solution:

notChopped = FullSimplify[RowReduce[something]]; keep = Not@*MatchQ[{0 ..}] /@ Chop[notChopped]; Pick[notChopped, keep] 
$\endgroup$
2
$\begingroup$

You can use DeleteCases with the pattern {__?(PossibleZeroQ @*Chop)} in the second argument:

lst = {{2., 1., 0}, {1.*^-11, 1.*^-11} , {0, 1.*^-11} , {1.*^-11, 0}}; DeleteCases[lst, {__?(PossibleZeroQ @*Chop)}] 

{{2., 1., 0}}

And alternative ways to use Pick:

Pick[lst, Unitize @ Total[Chop @ lst, {2}], 1] 

{{2., 1., 0}}

Pick[lst, Nand @@@ PossibleZeroQ @ Chop[lst]] 

{{2., 1., 0}}

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.