0
$\begingroup$

I have an equation of the form

f=a0+a1*Exp[-b1*x]+a2*Exp[-b2*x]+a3*Exp[-b3*x]+...+an*Exp[-bn*x]

with $n$ exponential terms. $a_i,b_i$ are real numbers (a result of some previous computation). My intention is to apply integral operator $\int_p^qdx$ to the function above. When number of terms in above equation becomes very large (in fact on my PC about greater than 30), the evaluation becomes very slow. So I thought why not bypass the integration step and use replacement rules because I know what the integral is going to look like. That is I want to do the following replacement, which I hope will speed up evaluation:

Exp[-b*x] -> (Exp[-b*q]-Exp[-b*p])/b
a0 -> a0(q-p)

I want to repeat that $a_i,b_i$, are real numbers which are output of some previous computation, and not just symbols, even though for generality I had to represent them as symbols here rather than as numbers.

I wish I could tell you what I tried, but honestly I have no clue how to proceed with this problem. How do I match patterns and do replacement in this case? Thanks in advance for any help.

P.S. I saw this post: Replace pattern for exponentials but wasn't helpful to me.

$\endgroup$
  • $\begingroup$ You say the $a_i$ are real numbers. How do these numbers relate to the $a$ in your rule a -> p - q? $\endgroup$ – m_goldberg Nov 23 '16 at 8:22
  • $\begingroup$ Why do you want a->p-q? Integrate[a Exp[-b x], {x, p, q}] yields $\frac{a \left(e^{-b p}-e^{-b q}\right)}{b}$. $\endgroup$ – corey979 Nov 23 '16 at 8:28
  • $\begingroup$ @m_goldberg, corey979 Sorry $a$ should be replaced by the quantity you have shown. $\endgroup$ – Deep Nov 23 '16 at 9:27
  • $\begingroup$ @corey979, m_goldberg The operator is $\int_p^q dx$, so the replacement for constant term should be $a0\to a0(q-p)$. Edited. $\endgroup$ – Deep Nov 23 '16 at 9:38
1
$\begingroup$
f = 3. + 2.6 Exp[-7.1 x] - 2.2 Exp[2 x]

rule = {Exp[b_*x] -> (Exp[b*q] - Exp[b*p])/b}

f /. rule /. {First[f] -> First[f] (p - q)}

enter image description here

The First[f] -> First[f] (p - q) is not very robust, though; works for this particular type of f.

$\endgroup$
  • $\begingroup$ +1 Beautiful. I guess I can always use ReplacePart for dealing with the constant term. $\endgroup$ – Deep Nov 23 '16 at 11:08
0
$\begingroup$

Working with version 10.1 this seems to works perfectly

f = a0 + a1*Exp[-Subscript[b, 1]*x] + a2*Exp[-Subscript[b, 2]*x] + 
  a3*Exp[-Subscript[b, 3]*x]
Exp[-b*x] -> (Exp[-b*q] - Exp[-b*p])/b
$\endgroup$
  • $\begingroup$ I would add one element to the rule and apply it: ` rule = {Exp[-b_x] -> (Exp[-bq] - Exp[-b*p])/b, a0 -> a0 (p - q)}; f /. rule` $\endgroup$ – Alexei Boulbitch Nov 23 '16 at 7:50
  • $\begingroup$ That's not an answer to this question, it doesn'r work on f = 3. + 2.6 Exp[-3.7 x]. The OP emphasized that a, b are some known particular numbers. @AlexeiBoulbitch's comment works, but partially, as it does not alter the as. $\endgroup$ – corey979 Nov 23 '16 at 7:54
  • $\begingroup$ @corey979 Right. This rule is better: rule = {Exp[b_*x] -> (Exp[b*q] - Exp[b*p])/b, a0 -> a0 (p - q)};. $\endgroup$ – Alexei Boulbitch Nov 23 '16 at 8:17
  • $\begingroup$ I'm not fully awaken yet, but I think the OP wants sth like rule = {a_ Exp[b_*x] -> (p - q) (Exp[b*q] - Exp[b*p])/b}. $\endgroup$ – corey979 Nov 23 '16 at 8:24
  • $\begingroup$ @corey979 You are right. Is {a_Exp[b_*x]} a valid pattern? $\endgroup$ – Deep Nov 23 '16 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.