0

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.

RossFe
  • 15
  • 3

1 Answers1

1

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}}}}
SPPearce
  • 5,653
  • 2
  • 18
  • 40
  • Incidentally I'm terrible at naming functions, and couldn't figure out how to write the Apply function without defining the intermediate function – SPPearce May 11 '16 at 12:45