matching or some other thing for sums of exponentials?
Subject: matching or some other thing for sums of exponentials?
From: Edwin Woollett
Date: Mon, 3 Oct 2011 21:01:30 -0700
On Oct. 3, 2011, dlakelan wrote:
------------------------------------
I have an expression that I get back from ode2 which contains things
like (a*%e^b + %e^c)
I would like to convert this to %e^c*(a*%e^(b-c)+1) or maybe in general
take the sum of two exponentials multiplied by something and do this:
a*exp(b) + c*exp(d) -> exp(d) * (a*(exp(b)/exp(d)) + c)
one of the reasons I want to do this is that many times this appears
inside a logarithm and the resulting simplifications will eliminate
intermediate overflows in floating point.
I can't figure out how to do this with matching / defrule, or with
fooling around using factor or factorsum or anything like that.
One of the problems seems to be the general problem that matching sub
parts of sums or products can be tricky.
any ideas?
------------------------------
Some code from my dirac2.mac code file (Maxima by Example,
Ch. 13) seems to work here:
(%i1) divout(expr,_aa%) :=
block ([jj,_newsum% ],
_newsum% : 0,
for jj thru length (expr) do
_newsum% : _newsum% + part(expr,jj)/_aa%,
_newsum% )$
(%i2) pullfac(eexpr,_n%) := _n%*divout (eexpr,_n%)$
(%i3) myee : (a*%e^b + %e^c)$
(%i4) pullfac (myee, %e^b);
b c - b
(%o4) %e (%e + a)
(%i5) pullfac (myee, %e^c);
b - c c
(%o5) (a %e + 1) %e
There are other tricks I use in my dirac package
batch files to express complicated expressions
in a form which can be compared with published
results.
Ted Woollett