0
$\begingroup$

I have to create my own function to solve equations (first and second degree). Assuming you have any input equation, how can I do to bring everything to the first side of the equation?

Example. I have:

eq=3*x+2==-2*x^2+4

but I'd like to have:

eq=2*x^2+3*x-2==0

Thanks.

$\endgroup$
  • $\begingroup$ (Subtract @@ eq) == 0 should work. $\endgroup$ – J. M.'s technical difficulties May 10 '16 at 12:03
  • 3
    $\begingroup$ Closely related: Does Mathematica have a built-in tool that allows one to operate on both sides of an equation? $\endgroup$ – Kuba May 10 '16 at 12:23
  • $\begingroup$ I use the similar (eq /. Equal -> Subtract) == 0, which will work at any level of a list $\endgroup$ – KraZug May 10 '16 at 12:45
  • $\begingroup$ @KraZug thanks for solution !! $\endgroup$ – RossFe May 10 '16 at 13:16
  • $\begingroup$ Actually I should have said that (eq /. Equal -> Subtract) works at any level of the list, but setting it to be equal to 0 would need Thread applying at the appropriate levels. If you just want the left hand side it works fine. $\endgroup$ – KraZug May 10 '16 at 13:29
0
$\begingroup$

I tend to use Equal -> Subtract to move from equalities to having everything on the left hand side, i.e.

(eq /. Equal -> Subtract)
-2 + 3 x + 2 x^2

If you want them to back to equations then here is a function that will allow it to be applied at any level of a list (rather than needing to use Thread):

rearrangeLeft[a_, b_] := a - b == 0
rearrangeLeftApply[x_] := x /. Equal -> rearrangeLeft

So applying to a nested list:

rearrangeLeftApply[{eq, {eq}, {{{eq}}}}]
{-2 + 3 x + 2 x^2 == 0, {-2 + 3 x + 2 x^2 == 0}, {{{-2 + 3 x + 2 x^2 == 0}}}}
| improve this answer | |
$\endgroup$
  • $\begingroup$ Incidentally I'm terrible at naming functions, and couldn't figure out how to write the Apply function without defining the intermediate function $\endgroup$ – KraZug May 11 '16 at 12:45

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