I am setting up a matrix system of differential equations that need to be solved. Some equations are redundant, and I have removed them using UpperTriangularize[]:

eqs = {{a[t]==0, b[t]==t},{b[t]==t,d[t]==t}};
eqs = UpperTriangularize[eqs];
(* {{a[t]==t, b[t]==t},{0,d[t]==t}} *)

I need to come up with a clever way to remove the zero elements from this list of lists (flattening it is an option). I have tried using DeleteCases[eqs,0,Inifity] and a solution based on Select[], but neither seemed to give the desired result.

  • $\begingroup$ How about Union@Flatten@eqs? Also, how do you generate eqs? (Or in other words, why do you have the duplicate equations anyway?) $\endgroup$ – sebhofer Oct 6 '17 at 8:18
  • 1
    $\begingroup$ DeleteCases[Flatten@eqs,0]? $\endgroup$ – mmeent Oct 6 '17 at 8:26
  • $\begingroup$ Ahh, I should point out, that I meant not to do use the UpperTriangularize... $\endgroup$ – sebhofer Oct 6 '17 at 8:31
  • 2
    $\begingroup$ @Julius I don't understand DeleteCases[Flatten@eqs,0] does not touch equations of the form a[t]==0. It will only touch entries in the flatten list that are an exact match to the pattern 0. Alternatively, DeleteCases[eqs, 0, {2}] gives the same output as your Table expression. $\endgroup$ – mmeent Oct 6 '17 at 8:53
  • 3
    $\begingroup$ By specifying Infinity as the level specification you are telling DeleteCases to delete expressions matching 0 at any level of eqn. This ignore heads so it will simply delete any 0 anywhere in the eqn $\endgroup$ – mmeent Oct 6 '17 at 9:03

Your Answer

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

Browse other questions tagged or ask your own question.