2
$\begingroup$

[Note: The given 2 solutions deal only with a simple example but not with the real problem]

Can I force MMA to use original expressions in a result of RowReduce instead of displaying only the condensed result?

For better understanding I give a simple example with Solve instead of RowReduce:

Solve[5x-2==3,x]
x->1

I want a result that includes original terms, e.g.

x->(3+2)/5

My code with RowReduce:

RowReduce[{{-1/(
     2 Sqrt[2]) (√(Sqrt[(s6^2 (s1^2 + s3^2) + 
            s4^2 (s1^2 + s5^2) + s2^2 (s3^2 + s5^2))^2 - 
          4 (s1^2 s3^2 + s1^2 s5^2 + s3^2 s5^2) (s2^2 s4^2 + 
             s2^2 s6^2 + s4^2 s6^2)] + s6^2 (s1^2 + s3^2) + 
         s4^2 (s1^2 + s5^2) + s2^2 (s3^2 + s5^2))), 0, 0, (s1 s4)/2, 
   0, -(1/2) (s1 s6)}, {0, -1/(
     2 Sqrt[2]) (√(Sqrt[(s6^2 (s1^2 + s3^2) + 
            s4^2 (s1^2 + s5^2) + s2^2 (s3^2 + s5^2))^2 - 
          4 (s1^2 s3^2 + s1^2 s5^2 + s3^2 s5^2) (s2^2 s4^2 + 
             s2^2 s6^2 + s4^2 s6^2)] + s6^2 (s1^2 + s3^2) + 
         s4^2 (s1^2 + s5^2) + s2^2 (s3^2 + s5^2))), -(1/2) (s2 s3), 
   0, (s2 s5)/2, 
   0}, {0, -(1/2) (s2 s3), -1/(
     2 Sqrt[2]) (√(Sqrt[(s6^2 (s1^2 + s3^2) + 
            s4^2 (s1^2 + s5^2) + s2^2 (s3^2 + s5^2))^2 - 
          4 (s1^2 s3^2 + s1^2 s5^2 + s3^2 s5^2) (s2^2 s4^2 + 
             s2^2 s6^2 + s4^2 s6^2)] + s6^2 (s1^2 + s3^2) + 
         s4^2 (s1^2 + s5^2) + s2^2 (s3^2 + s5^2))), 0, 0, (s3 s6)/
   2}, {(s1 s4)/2, 0, 
   0, -1/(2 Sqrt[
      2]) (√(Sqrt[(s6^2 (s1^2 + s3^2) + s4^2 (s1^2 + s5^2) + 
            s2^2 (s3^2 + s5^2))^2 - 
          4 (s1^2 s3^2 + s1^2 s5^2 + s3^2 s5^2) (s2^2 s4^2 + 
             s2^2 s6^2 + s4^2 s6^2)] + s6^2 (s1^2 + s3^2) + 
         s4^2 (s1^2 + s5^2) + s2^2 (s3^2 + s5^2))), -(1/2) (s4 s5), 
   0}, {0, (s2 s5)/2, 
   0, -(1/2) (s4 s5), -1/(
     2 Sqrt[2]) (√(Sqrt[(s6^2 (s1^2 + s3^2) + 
            s4^2 (s1^2 + s5^2) + s2^2 (s3^2 + s5^2))^2 - 
          4 (s1^2 s3^2 + s1^2 s5^2 + s3^2 s5^2) (s2^2 s4^2 + 
             s2^2 s6^2 + s4^2 s6^2)] + s6^2 (s1^2 + s3^2) + 
         s4^2 (s1^2 + s5^2) + s2^2 (s3^2 + s5^2))), 
   0}, {-(1/2) (s1 s6), 0, (s3 s6)/2, 0, 
   0, -1/(2 Sqrt[
      2]) (√(Sqrt[(s6^2 (s1^2 + s3^2) + s4^2 (s1^2 + s5^2) + 
            s2^2 (s3^2 + s5^2))^2 - 
          4 (s1^2 s3^2 + s1^2 s5^2 + s3^2 s5^2) (s2^2 s4^2 + 
             s2^2 s6^2 + s4^2 s6^2)] + s6^2 (s1^2 + s3^2) + 
         s4^2 (s1^2 + s5^2) + s2^2 (s3^2 + s5^2)))}}]

In the solution I would like to see all roots as they appear in the above expression so that I can easily associate the terms.

This answer about RowReduce does not work in my case.

$\endgroup$
3
  • $\begingroup$ I don't think can be achieved for Solve without rewriting Solve by yourself. Also, you should specify more precisely what you mean by "any other operation" because there are thousands of different "operations" in Mathematica, working very differently from each other. You probably have some particular problem in mind – show it explicitly. $\endgroup$
    – Domen
    Mar 22, 2023 at 14:22
  • 1
    $\begingroup$ It is of no use if you give some completely different example with Solve when you actually want a solution for RowReduce. Show the actual problem you have. It can be simplified (like using a smaller, simpler matrix), but not completely different. $\endgroup$
    – Domen
    Mar 22, 2023 at 14:33
  • 1
    $\begingroup$ @granularbastard, then show a smaller matrix. If you have mat, post mat[[1;;2, 1;;2]], or make up a simpler matrix! Stop other people wasting time, and answering your question by using Solve. $\endgroup$
    – Domen
    Mar 22, 2023 at 17:09

2 Answers 2

2
$\begingroup$
Clear["Global`*"]

eqn = 5 x - 2 == 3;

eqn2 = eqn /. n_Integer :> Sign[n]*ToString[Abs[n]];

sol = Solve[eqn2, x][[1]]

enter image description here

sol2 = sol /. str_String :> ToExpression[str]

{x -> 1}

EDIT: For a slightly more complicated equation

eqn = 5 x - 2 == 3 x^2;

eqn2 = eqn /. a_Integer*x^n_. :> Sign[a]*ToString[a]*x^n;

sol = Solve[eqn2, x]

enter image description here

sol2 = sol /. str_String :> ToExpression[str]

(* {{x -> 2/3}, {x -> 1}} *)

eqn /. sol2

(* {True, True} *)
$\endgroup$
0
1
$\begingroup$

I think you're going to need to decide ahead of time which parts of your equation are the terms in which you want your solution to appear. Then you can use dummy variables for those terms. You will also need some way to stop evaluation of your final expression, and some form of Hold* is appropriate for that.

For example

eq1 = a x - b == c;
sols1 = Solve[eq1, x];
MapAt[HoldForm, sols1, {All, All, 2}] /. {a -> 5, b -> 2, c -> 3}

{{x -> (2 + 3)/5}} (the HoldForm is there, just suppressed in the display).

Or

eq2 = a x - b == c x^2;
sols2 = Solve[eq, x];
MapAt[HoldForm, sols2, {All, All, 2}] /. {a -> 5, b -> 2, c -> 3}

{{x ->-1/2*(-1*5 + Sqrt[5^2 - 4*2*3])/3}, {x ->(5 + Sqrt[5^2 - 4*2*3])/(2*3)}}

Or even just apply the HoldForm from the beginning to the terms you want to preserve:

eq3 = HoldForm[5] x - HoldForm[2] == HoldForm[3] x^2;
sols3 = Solve[eq3, x]

(Same result in appearance, but the HoldForm is in different places.)

$\endgroup$
4
  • $\begingroup$ I don't know what result you want, so I don't know. At the time I posted this answer, there was no RowReduce example, so you've moved the goalposts. But the principle is that to get the structure you want in the result you need to determine which symbols to hold. If that doesn't work with RowReduce, or if it just doesn't work in your context, well, then, it doesn't work. Sorry. I answered the question that was originally asked. $\endgroup$
    – lericr
    Mar 22, 2023 at 17:38
  • $\begingroup$ At the time of asking the question it is not clear if a solution for a simple example can be applied in general. $\endgroup$ Mar 22, 2023 at 17:40
  • 1
    $\begingroup$ The burden is on the asker to ask a well-formed and relevant question. The burden is not on the answerer to guess what generalizations the asker is keeping secret. $\endgroup$
    – lericr
    Mar 22, 2023 at 17:50
  • $\begingroup$ The original question states "My question concerns not only Solve but any operation." This also includes RowReduce. Actually I thought there is an option that works for any operation. $\endgroup$ Mar 22, 2023 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.