8

I need to row-reduce the following matrix,

{{a, b, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, a1, b1, 0, 0, 1},
 {0, 0, c, d, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, c1 ,d1, 1}, 
 {0, b1, 0, -d1, a, 0, -c, 0, 0}, {-b1, 0, d1, 0, b, 0, -d, 0, 0}, 
 {0, -a1, 0, c1, 0, a, 0, -c, 0}, {a1, 0, -c1, 0, 0, b, 0, -d, 0}}

After Mathematica does the computation, the bottom row is a row of zeros. This is to be expected (based on my problem). However, the second to bottom row is a row of zeros with a 1 at the end. When the algebra is done "by hand", one really should obtain a row of zeros with some linear combination of the variables involved instead of 1. Mathematica divides by this expression. This expression could be zero, and in my problem, I want that last matrix entry to be zero. How can I tell Mathematica not to simplify?

If you be kind,can you also upload the answer you are getting, so I can double-check with mine?

Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • From what you write it seems likely that you have given values to the variables in question at some time previous to your matrix calculation. You should clear those variables before making the computation. – m_goldberg Jul 01 '17 at 06:30
  • When the algebra is done "by hand" Can you show the hand solution then which is different from Mathematica solution? – Nasser Jul 01 '17 at 07:05
  • @Nasser Yes. Set a = a1 = 1, b = b1 = 0, c = c1 = 0, d = d1 = 1. Get a different answer. Mathematica makes a mistake because it divides by zero in the general variable case. – Donald Trump Jul 01 '17 at 07:09
  • 1
    I am not sure I understand. But you can try (RowReduce[mat, ZeroTest -> (PossibleZeroQ[Simplify[#]] &)]) // MatrixForm if you want to see the content not simplified. But your question is not clear. Are you saying the second row from the bottom is supposed to be all zeros and not have 1 as it last entry? – Nasser Jul 01 '17 at 07:14
  • @Nasser Tell mathematica to keep (x-y)/(x-y) as (x-y)/(x-y), not to simplify it to 1. Since (x-y)/(x-y) is not equal to 1 in the special case when x,y are the same numbers. How can I tell mathematica to keep the fractions. – Donald Trump Jul 01 '17 at 07:18
  • 1
    I do not think it is possible to tell M that x/x is not 1 when x is symbol with no value. At least I do not know how to do it. Assuming[x == 0, Simplify[x/x]] gives 1 always. I think the front end replaces x/x by 1 before the kernel even gets hold of it. But I am not sure. – Nasser Jul 01 '17 at 07:37
  • Reduced echelon form, by definition, has a leading 1 in each row, and that, typically, is what Mathematica will give you. When you're doing the calculation by hand, you can see better what's going on in the guts, and stop before you get to the end. In finding reduced echelon form, Mathematica makes various nondegeneracy assumptions (eg, parameters not being zero), which can sometimes be hard to track. If @Nasser's comment isn't what you're after, a bit of context to your problem might help people give you an alternative approach. – aardvark2012 Jul 01 '17 at 10:22
  • @Nasser Perhaps your displayRREF[] could be used, if the last divide is omitted. One problem with this Q, I suspect, is that the answer (when leading coefficient is not reduced to 1) is not unique but depends on the pivots. – Michael E2 Jul 01 '17 at 14:53
  • You could use my StrictFunctionDomain function to get assumptions that Mathematica makes calculating "generic" solution: assum = StrictFunctionDomain@Flatten@RowReduce@mat (* a != 0 && a1 != 0 && c != 0 && c1 != 0 && -a1 b c c1 + a a1 c1 d != 0 *) where mat is your matrix. Then you could analyze distinct special cases separately: BooleanConvert[Not@assum, "ANF"], note that in general number of such special cases suffers from combinatorial explosion, here there are 31 of them. – jkuczm Jul 01 '17 at 15:47
  • Hello @MichaelE2. The function displayRREF only works on square matrices, so I could not use it for this. The matrix in this post is 8 rows by 9 columns. – Nasser Jul 01 '17 at 20:15

1 Answers1

6

You can choose a different ZeroTest option:

RowReduce[
    {
    {a,b,0,0,0,0,0,0,1},
    {0,0,0,0,a1,b1,0,0,1},
    {0,0,c,d,0,0,0,0,1},
    {0,0,0,0,0,0,c1,d1,1},
    {0,b1,0,-d1,a,0,-c,0,0},
    {-b1,0,d1,0,b,0,-d,0,0},
    {0,-a1,0,c1,0,a,0,-c,0},
    {a1,0,-c1,0,0,b,0,-d,0}
    },
    ZeroTest->PossibleZeroQ
] //TeXForm

$\left( \begin{array}{ccccccccc} 1 & 0 & 0 & 0 & 0 & \frac{b}{\text{a1}} & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & -\frac{a}{\text{a1}} & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & \frac{d}{\text{c1}} & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & -\frac{c}{\text{c1}} & 0 \\ 0 & 0 & 0 & 0 & 1 & \frac{\text{b1}}{\text{a1}} & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & \frac{\text{d1}}{\text{c1}} & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & \text{a1} \text{c1} (\text{b1} c (\text{a1} b c \text{c1}-a \text{a1} \text{c1} d)-c (a \text{a1} d-\text{a1} b c) (\text{a1} \text{d1}-\text{b1} \text{c1}))-\text{a1}^2 c (\text{a1} b c \text{c1}-a \text{a1} \text{c1} d) \text{d1} & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & \text{a1} \text{c1} \left(b \text{b1} c^2 (\text{a1} b c \text{c1}-a \text{a1} \text{c1} d)-c (a \text{a1} d-\text{a1} b c) (a \text{a1} d \text{d1}-b \text{b1} c \text{c1})\right)-a \text{a1}^2 c d (\text{a1} b c \text{c1}-a \text{a1} \text{c1} d) \text{d1} & 0 \\ \end{array} \right)$

Carl Woll
  • 130,679
  • 6
  • 243
  • 355