0
$\begingroup$

I am trying to find coefficient of an exponent term in an expression. For example, consider

tt = E^(I*T0*(ω+σ));

Doing

Coefficient[tt, E^(I*T0*(ω+σ))]
(* 1 *)

gives 1. However,

Coefficient[tt, E^(I*T0*ω)]
(* 0 *)

this returns 0. How do I obtain $e^{i*T0*\sigma}$ as output instead of $0$?

I thought PowerExpand will work, but it also did not. I couldn't find the command to expand exponents.

PS: The expression tt is just a dummy expression, my original expression is really big and contains a lot of terms.

$\endgroup$
  • $\begingroup$ tt / E^(I*T0*ω)? $\endgroup$ – AccidentalFourierTransform Jul 6 at 20:15
  • $\begingroup$ Actually the expression is really big, it contains a lot of other terms. That's why this method won't work. I'll add it in the question, thanks for the heads up $\endgroup$ – Aakash Gupta Jul 6 at 20:17
  • $\begingroup$ The issue is that, from a math pov, the problem is simply ill-defined. It is meaningless to state that the coefficient of $f(t)$ in an arbitrary expression $F(t)$ is $g(t)$. You can do that, canonically, if (say) $F$ is a polynomial and $f$ a monomial (and $g$ is just a constant). But, in more general terms, the problem is not well-posed (e.g. you can always introduce factors of $1=f(t)/f(t)$ everywhere, which changes the putative $g(t)$). You will have to be much more explicit in what $F$ is, and what are your rules, if you want the problem to be solvable. Only then can MMA try to solve it. $\endgroup$ – AccidentalFourierTransform Jul 6 at 20:36
1
$\begingroup$

This should work for a lot of cases:

Coefficient[Expand[tt] /. E^(I*T0*(ω + x_.) + y_.) -> U * E^(I*T0*x + y), U]
(*    E^(I*T0*σ)    *)

If U happens to be a symbol that you use somewhere else in the code, then just use some different symbol here instead of U.

Updated version: Thanks to @AccidentalFourierTransform for pointing out that localizing U is required.

getcoeff[t_] := Module[{U},
  Coefficient[Expand[t] /. 
    E^(a_.*(b_.*ω + x_.) + y_.) /; a*b == I*T0 -> U*E^(a*x + y),
    U]]

This also works with cases like

getcoeff[E^(1/2*I*T0*(2ω+6))]
(*    E^(3*I*T0)    *)
$\endgroup$
  • $\begingroup$ You could Block the variable U just to be sure. $\endgroup$ – AccidentalFourierTransform Jul 6 at 20:53
  • $\begingroup$ Is _.a new feature in MMA12? $\endgroup$ – Ulrich Neumann Jul 7 at 12:53
  • 1
    $\begingroup$ @UlrichNeumann no, Default has been around since version 1. See this tutorial. $\endgroup$ – Roman Jul 7 at 12:57

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.