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


Groups > comp.soft-sys.math.mathematica > #13448 > unrolled thread

Re: Differencing two equations

Started byBob Hanlon <hanlonr357@gmail.com>
First post2013-02-11 09:36 +0000
Last post2013-08-04 09:16 +0000
Articles 3 — 2 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.


Contents

  Re: Differencing two equations Bob Hanlon <hanlonr357@gmail.com> - 2013-02-11 09:36 +0000
    Re: Differencing two equations nma%12000.org@gtempaccount.com - 2013-08-04 09:15 +0000
    Re: Differencing two equations nma%12000.org@gtempaccount.com - 2013-08-04 09:16 +0000

#13448 — Re: Differencing two equations

FromBob Hanlon <hanlonr357@gmail.com>
Date2013-02-11 09:36 +0000
SubjectRe: Differencing two equations
Message-ID<kfae39$m53$1@smc.vnet.net>
eqnOperate[eqn1_, eqn2_, f_] :=
  Equal @@ f @@ {List @@ eqn1, List @@ eqn2};


eqnOperate[a == r, b == s, Subtract]

a - b == r - s


eqnOperate[a == r, b == s, Plus]

a + b == r + s


eqnOperate[a == r, b == s, Times]

a b == r s


eqnOperate[a == r, b == s, Divide]

a/b == r/s


eqnOperate[a == r, b == s, Power[#1, #2] &]

a^b == r^s


Bob Hanlon


On Sun, 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.
>

[toc] | [next] | [standalone]


#15276

Fromnma%12000.org@gtempaccount.com
Date2013-08-04 09:15 +0000
Message-ID<ktl63f$h7r$1@smc.vnet.net>
In reply to#13448
On Monday, February 11, 2013 3:36:41 AM UTC-6, Bob Hanlon wrote:
> eqnOperate[eqn1_, eqn2_, f_] :=
> 
>   Equal @@ f @@ {List @@ eqn1, List @@ eqn2};

This is a follow up on my last post. It was a user error on my part.
I passed it invalid input. I fixed my input and the above
function works as expected.

thanks,
--Nasser

[toc] | [prev] | [next] | [standalone]


#15277

Fromnma%12000.org@gtempaccount.com
Date2013-08-04 09:16 +0000
Message-ID<ktl64q$h81$1@smc.vnet.net>
In reply to#13448
On Monday, February 11, 2013 3:36:41 AM UTC-6, Bob Hanlon wrote:
> eqnOperate[eqn1_, eqn2_, f_] :=
> 
>   Equal @@ f @@ {List @@ eqn1, List @@ eqn2};
> 
> eqnOperate[a == r, b == s, Subtract]
> 
> 
> a - b == r - s
> 

Hello;

Do you know why this case of subtracting 2 equations does not produce the expected result using your function above?

------------------------------

eqnOperate[eqn1_, eqn2_, f_] := 
  Equal @@ f @@ {List @@ eqn1, List @@ eqn2}; 

eqn1 = 8*(-f[-h + x] + f[h + x] == 2*h*Derivative[1][f][x]); 
eqn2 = -f[-2*h + x] + f[2*h + x] == 
   4*h*Derivative[1][f][x] + (8/3)*h^3*Derivative[3][f][x] + 
         (8/15)*h^5*Derivative[5][f][x]; 

eqnOperate[eqn1, eqn2, Subtract]
-------------------------------------

Out[4]= 8 + f[-2*h + x] - 
  f[2*h + x] == (-f[-h + x] + f[h + x] == 2*h*Derivative[1][f][x]) - 
  4*h*Derivative[1][f][x] - 
     (8/3)*h^3*Derivative[3][f][x] - (8/15)*h^5*Derivative[5][f][x]

You can see the result has too many '==' inside it. 

thanks,
--Nasser

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web