MATLAB Answers


Factor symbolic expression involving exp()

Asked by Philip
on 13 Sep 2015
Latest activity Commented on by Philip
on 13 Sep 2015
I have a symbolic function exp(a+b), and would like to factor out A=exp(a) to produce exp(a+b) = A*exp(b), but I cannot figure out how to do this in MATLAB. Below is my attempt:
syms a b A
X = exp(a+b)
Y = subs(X,exp(a),A) % = A*exp(b)
however, Y = exp(a+b). For some reason, MATLAB cannot determine exp(a+b) = exp(a)*exp(b) = A*exp(b).
Any help is greatly appreciated.


Sign in to comment.

1 Answer

Answer by Walter Roberson
on 13 Sep 2015
 Accepted Answer

subs() replaces one sub-expression tree with a different sub-expression tree. exp(a) is not present as a sub-expression in exp(a+b) so you cannot use subs() to make that replacement in it.
What might work is
Y = subs(expand(X), exp(a), A);


Thank you. That works great. What if I had:
X = exp(2*a+b)
and wanted to produce Y = A^2 * exp(b), where A=exp(a). How could I get this result (just using expand doesn't work).
Y = expand(subs(X, a, ln(A)))
That's perfect! Thanks again.

Sign in to comment.