0
$\begingroup$

The following expression is a short excerpt from a much longer expression I have:

exp = a E^(I (k x - t \[Omega])) \[Alpha]1 + 
     a E^(-k x - I t \[Omega]) R0 \[Alpha]2 + 
     a E^(-3 k x - 3 I t \[Omega]) R0 \[Alpha]3 + 
    a E^(I (5 k x - 5 t \[Omega])) \[Alpha]5;

I need a basic command that checks the above expression and issues an alert if any of the following conditions are not met:

1- Sign of k in the exponential must be positive if "a" is not multiplied by R0.

2- Sign of k in the exponential must be negative if "a" is multiplied by R0.

For example, the command should give me a warning that the last term in expEroor violates either conditions mentioned above:

  expError = a E^(I (k x - t \[Omega])) \[Alpha]1 + 
    a E^(-k x - I t \[Omega]) R0 \[Alpha]2 + 
    a E^(-3 k x - 3 I t \[Omega]) R0 \[Alpha]3 + 
     a R0 E^(I (5 k x - 5 t \[Omega])) \[Alpha]5;

Thanks in advance for help.

$\endgroup$
0

1 Answer 1

1
$\begingroup$

One could use

(* test a single term *)
coeff[expr_]:=expr/.Thread[Variables[expr]->1]/.Complex[0,a_]:>a;
test[(c_:1)*Power[E,b_]]:=With[{s=coeff[D[b,k]]},And[
    Implies[FreeQ[c,R0],s>0],
    Implies[Not[FreeQ[c,R0]],s<0]
]];

(* select terms that do not pass the test  *)
Select[List@@expError, Not[test[#]===True]&]

(* { a E^(I (5 k x-5 t ω)) R0 α5} *)

The function coeff uses this answer.

$\endgroup$
1
  • $\begingroup$ Thanks for your answer. However, there are terms that don’t have “I” multiplied by “k” in the exponent. $\endgroup$
    – qahtah
    Oct 10, 2022 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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