Question

As am new to mathematica, pls do help me what is happening in the code given in mathematica. I want to write it in matlab.

Clear[t, k, w, fg, g];   
t = 0;     
k = 0;      
For[a = 1, a < 26, t = t1, t1 = t + 8];   
g = ((−1)^a+1)∗ Integrate[Exp[−i ∗ w ∗ z],{z,t,t1}]; k = k + g; a++);    
fg[w_] = Re[k ∗ Conjugate[k]];      
li = Plot[fg[w], {w, 0.1, 0.7}], PlotRange → All, Frame → True]       
want to know how the for loop is working here.?

actual problem is integrate the function with respect to limits for a set of w values and with the changing of limits again integrating with same set of w values and summing up those integrated values. where the input for 'w' values are taken here?

Was it helpful?

Solution

My best guess at what this should look like:

 Clear[w];
 t = 0; k = 0;
 For[a = 1, a < 26, a++,
       g = ((-1)^a + 1)  Integrate[Exp[ -I   w   z], {z, t, t + 8}];
       k += g;
       t += 8];
 fg[w_] = Re[k   Conjugate[k]];
 Plot[fg[w], {w, 0.1, 0.7}, PlotRange -> All]

enter image description here

in more mathematicaesque form:

Clear[w]
fg[w_] = Re[#   Conjugate[#]] &@ 
          Sum[ ((-1)^a + 1) 
            8 Integrate[Exp[-I   w   (z + a - 1)  8 ], {z, 0, 1}] ,
               {a, 25}];
 Plot[fg[w], {w, 0.1, 0.7}, PlotRange -> All]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top