0
$\begingroup$

I want to implement this recursive formula:

enter image description here

"j" is imaginary symbol (i.e. j = I = Sqrt[-1]); I have written my code as:

expR[0, theta_] := Exp[0] = 1.;
expR[m_, theta_] := Exp[-I m theta] = Exp[-I (m - 1) theta] Exp[-I theta];

but it not works, for example my thetalist could be:

thetalist = RandomReal[2., {5}]  (*{1.36386, 0.720838, 0.504584, 0.154796, 1.83031}*)

but I always got warning when testing something for example:

expR[20, thetalist]

Set::write: Tag Exp in Exp[{0. -27.2773 I,0. -14.4168 I,0. -10.0917 I,0. -3.09593 I,0. -36.6061 I}] is Protected.

$\endgroup$

1 Answer 1

2
$\begingroup$
thetalist = {1.36386, 0.720838, 0.504584, 0.154796, 1.83031};

Method 1:

Clear[expR]

expR[0, theta_] = 1;

expR[m_Integer?Positive, theta_] := 
 expR[m, theta] = expR[m - 1, theta]*Exp[-I*theta]

list11 = expR[#, theta] & /@ Range[0, 20];

list11[[1 ;; 5]]

(* {1, E^(-I theta), E^(-2 I theta), E^(-3 I theta), E^(-4 I theta)} *)

More generally,

FindSequenceFunction[list11[[2 ;; 10]], m] // PowerExpand

(* E^(-I m theta) *)

list12 = expR[20, thetalist]

(* {-0.542712 - 0.839919 I, -0.275965 - 0.961168 I, -0.785742 + 
  0.618555 I, -0.998957 - 0.0456568 I, 0.459902 + 0.88797 I} *)

list12 == Exp[-I 20 thetalist]

(* True *)

Method 2 : Using RSolve

Clear[expR]

expR[m_, theta_] = 
 expR[m, theta] /. 
   RSolve[{expR[0, theta] == 1, 
      expR[m, theta] == expR[m - 1, theta]*Exp[-I*theta]}, 
     expR[m, theta], {m, theta}][[1]] // PowerExpand

(* E^(-I m theta) *)

which is identical to the result from FindSequenceFunction above

list21 = expR[#, theta] & /@ Range[0, 20];

list22 = expR[20, thetalist]

(* {-0.542712 - 0.839919 I, -0.275965 - 0.961168 I, -0.785742 + 
  0.618555 I, -0.998957 - 0.0456568 I, 0.459902 + 0.88797 I} *)

list22 == Exp[-I 20 thetalist]

(* True *)

Verifying that both methods are equivalent for nonnegative, integer m

list11 == list21

(* True *)

list12 == list22

(* True *)
$\endgroup$
1
  • $\begingroup$ Thanks for the detailed answer! $\endgroup$ Commented Dec 19, 2018 at 4:51

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.