Re: Adding equations
- To: mathgroup at smc.vnet.net
- Subject: [mg14402] Re: [mg14342] Adding equations
- From: BobHanlon at aol.com
- Date: Sun, 18 Oct 1998 15:10:07 -0400
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 10/15/98 5:13:03 AM, lwalker701 at earthlink.net wrote: >I've been trying to add two equations as follows: > >In[4]:= > a==b; >In[5]:= > c==d; >In[6]:= > %4+%5 >Out[6]= > (a==b)+(c==d) > >The result I was looking for is (a+c)==(b+d). The following works but it >seems clumsy. In[7]:= > %4[[1]]+%5[[1]]==%4[[2]]+%5[[2]] Out[7]= > a+c==b+d >Is there a way to elegantly add (sub, mult, div) two equations? Also is >there an elegant way to add (sub, mult, div) an expression to both >sides of an equation? One approach: eqnAdd[(a_) == (b_), (c_) == (d_)] := a + c == b + d; eqnAdd[a_, (c_) == (d_)] := a + c == a + d; eqnAdd[a_, x_List] := (eqnAdd[a, #1] & ) /@ x; eqnMult[a_, (b_) == (c_)] := a*b == a*c; eqnMult[a_, x_List] := (eqnMult[a, #1] & ) /@ x; eqnSqrt[(a_) == (b_)] := {Sqrt[a] == Sqrt[b], Sqrt[a] == -Sqrt[b]}; a*x^2 + b*x + c == 0; eqnMult[4*a, %] 4*a*(c + b*x + a*x^2) == 0 eqnAdd[b^2 - 4*a*c, %] b^2 - 4*a*c + 4*a*(c + b*x + a*x^2) == b^2 - 4*a*c ExpandAll[%] b^2 + 4*a*b*x + 4*a^2*x^2 == b^2 - 4*a*c Factor /@ % (b + 2*a*x)^2 == b^2 - 4*a*c eqnSqrt[%] {Sqrt[(b + 2*a*x)^2] == Sqrt[b^2 - 4*a*c], Sqrt[(b + 2*a*x)^2] == -Sqrt[b^2 - 4*a*c]} PowerExpand[%] {b + 2*a*x == Sqrt[b^2 - 4*a*c], b + 2*a*x == -Sqrt[b^2 - 4*a*c]} eqnAdd[-b, %] {2*a*x == -b + Sqrt[b^2 - 4*a*c], 2*a*x == -b - Sqrt[b^2 - 4*a*c]} eqnMult[1/(2*a), %] {x == (-b + Sqrt[b^2 - 4*a*c])/(2*a), x == (-b - Sqrt[b^2 - 4*a*c])/(2*a)} Bob Hanlon