Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #13453 > unrolled thread
| Started by | Murray Eisenberg <murrayeisenberg@gmail.com> |
|---|---|
| First post | 2013-02-11 09:36 +0000 |
| Last post | 2013-08-06 02:53 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Differencing two equations Murray Eisenberg <murrayeisenberg@gmail.com> - 2013-02-11 09:36 +0000
Re: Differencing two equations David Bailey <dave@removedbailey.co.uk> - 2013-08-05 10:03 +0000
Re: Differencing two equations "djmpark" <djmpark@comcast.net> - 2013-08-06 02:53 +0000
| From | Murray Eisenberg <murrayeisenberg@gmail.com> |
|---|---|
| Date | 2013-02-11 09:36 +0000 |
| Subject | Re: Differencing two equations |
| Message-ID | <kfae2p$m4o$1@smc.vnet.net> |
Yeah, Mathematica stubbornly refuses to thread Equal over the difference. I seem to recall that there are good design reasons for that.
The following works, but of course is more involved than one might like:
Equal @@ Subtract @@@ {a == r, b == s}
Which is an abbreviated form of:
Apply[Equal, Apply[Subtract, {a == r, b == s}, 1]]
Essentially, you're taking out the equalities and after subtractions putting an equality back.
On Feb 10, 2013, at 3:24 AM, 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.
---
Murray Eisenberg murray@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2838 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
[toc] | [next] | [standalone]
| From | David Bailey <dave@removedbailey.co.uk> |
|---|---|
| Date | 2013-08-05 10:03 +0000 |
| Message-ID | <ktnt9j$n3h$1@smc.vnet.net> |
| In reply to | #13453 |
On 11/02/2013 09:36, Murray Eisenberg wrote:> Yeah, Mathematica
stubbornly refuses t
>
>> 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 think it helps to manipulate algebraic expressions in a way that makes
it easy to understand when you come back to a notebook sometime later!
So my approach would be to define a function to subtract equations, so
that it is pretty obvious what is going on!
In[16]:= subtract[a1_ == a2_, b1_ == b2_] := (a1 - b1) == (a2 - b2)
In[17]:= subtract[x + 3 y == 6, x - y == 2]
Out[17]= 4 y == 4
This also has the advantage that if you accidentally supply an argument
that is not an equality, you will not get a misleading answer!
A slightly more general function might take a third argument that would
act as a multiplier of the second equality:
In[20]:= combine[a1_ == a2_, b1_ == b2_,
k_] := (a1 + k b1) == (a2 + k b2)
In[21]:= combine[x + 3 y == 6, x - y == 2, -1]
Out[21]= 4 y == 4
In[23]:= combine[x + 3 y == 6, x - y == 2, 3] // Simplify
Out[23]= x == 3
(You could also include the Simplify as part of your combine function)
David Bailey
http://www.dbaileyconsultancy.co.uk
[toc] | [prev] | [next] | [standalone]
| From | "djmpark" <djmpark@comcast.net> |
|---|---|
| Date | 2013-08-06 02:53 +0000 |
| Message-ID | <ktpofm$rg3$1@smc.vnet.net> |
| In reply to | #13453 |
Inner is also sometimes a useful construct for this.
eqn1 = a1 == a2;
eqn2 = b1 == b2;
Inner[Plus, eqn1, eqn2, Equal]
a1 + b1 == a2 + b2
Inner[Plus, eqn1, Minus /@ eqn2, Equal]
a1 - b1 == a2 - b2
Inner[Plus, eqn1, 3 # & /@ eqn2, Equal]
a1 + 3 b1 == a2 + 3 b2
David Park
djmpark@comcast.net
http://home.comcast.net/~djmpark/index.html
From: David Bailey [mailto:dave@removedbailey.co.uk]
On 11/02/2013 09:36, Murray Eisenberg wrote:> Yeah, Mathematica stubbornly
refuses t > >> 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 think it helps to manipulate algebraic expressions in a way that makes it
easy to understand when you come back to a notebook sometime later!
So my approach would be to define a function to subtract equations, so that
it is pretty obvious what is going on!
In[16]:= subtract[a1_ == a2_, b1_ == b2_] := (a1 - b1) == (a2 - b2)
In[17]:= subtract[x + 3 y == 6, x - y == 2]
Out[17]= 4 y == 4
This also has the advantage that if you accidentally supply an argument that
is not an equality, you will not get a misleading answer!
A slightly more general function might take a third argument that would act
as a multiplier of the second equality:
In[20]:= combine[a1_ == a2_, b1_ == b2_,
k_] := (a1 + k b1) == (a2 + k b2)
In[21]:= combine[x + 3 y == 6, x - y == 2, -1]
Out[21]= 4 y == 4
In[23]:= combine[x + 3 y == 6, x - y == 2, 3] // Simplify
Out[23]= x == 3
(You could also include the Simplify as part of your combine function)
David Bailey
http://www.dbaileyconsultancy.co.uk
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web