Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13460

Re: Differencing two equations

From David Bailey <dave@removedbailey.co.uk>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Differencing two equations
Date 2013-02-12 08:23 +0000
Message-ID <kfcu5p$srj$1@smc.vnet.net> (permalink)
References <kf7m3q$fgi$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


On 10/02/2013 08:35, g.c.b.at.home@gmail.com wrote:
> I'm brand new to Mathematica, so I apologize for the naive questions...
>
> I'm trying to figure out how to difference two equations.  Basically if I have:
> a==r
> b==s
>
> I'd like to get:
> a-b == r-s
>
> What I'm getting is more like (a==r) - (b==s).  I'm not sure how that's a useful result, but is there a function to do what I'm looking for?
>
> A quick search of the archives seem to bring up ways of doing this from using transformation rules to swap heads to unlocking the Equals operator and hacking its behavior.  I'd like to avoid doing that kind of rewiring for a simple operation, and I'd like to keep the syntax clean.
>
> The Core Language documentation makes a big point of how everything is basically a list with different heads.  In this case, what I'm trying to do would work if it were treated as a list ({a,b}-{r,s} returns {a-b,r-s}) but doesn't work under Equal.
>
> Thanks for any suggestions.
>

I would define a function thus:

equationSubtract[x1_ == y1_, x2_ == y2_] := (x1 - x2) == (y1 - y2);

(If you use it a lot, you might want to put it somewhere do it is auto 
loaded).

In[9]:= equationSubtract[a == r, b == s]

Out[9]= a - b == r - s

A slightly better version might have a third optional argument to supply 
a multiplier:

equationSubtract[x1_ == y1_, x2_ == y2_,
   m_: 1] := (x1 - m x2) == ( y1 - m y2);

In[5]:= equationSubtract[a == r, b == s, 2]

Out[5]= a - 2 b == r - 2 s

This function would still handle the 2-argument case.

In general, I don't believe in writing complicated syntax to do an 
individual algebraic manipulation (because if you get it wrong, you may 
not notice the wrong answer!). It is better to write a function once, 
test it, and use it when you need it - as I have done here.

David Bailey
http://www.dbaileyconsultancy.co.uk


Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Differencing two equations g.c.b.at.home@gmail.com - 2013-02-10 08:35 +0000
  Re: Differencing two equations Ray Koopman <koopman@sfu.ca> - 2013-02-11 09:36 +0000
  Re: Differencing two equations G B <g.c.b.at.home@gmail.com> - 2013-02-12 08:23 +0000
  Re: Differencing two equations David Bailey <dave@removedbailey.co.uk> - 2013-02-12 08:23 +0000
  Re: Differencing two equations "djmpark" <djmpark@comcast.net> - 2013-02-13 09:47 +0000
  Re: Differencing two equations Best Gregory <g.c.b.at.home@gmail.com> - 2013-02-13 09:47 +0000
  Re: Differencing two equations John Doty <noqsiaerospace@gmail.com> - 2013-02-14 07:09 +0000
  Re: Differencing two equations Youngjoo Chung <ychung12@gmail.com> - 2013-09-08 06:56 +0000

csiph-web