title: Matlab Integration in a loop
body: <p>I am working in matlab the M-QAM modulation with Rayleigh fading, and i have a little problem with the integration part, i have made that code with an aproximation:</p>
  
  <pre><code>function y = m_qam_ray( M )
  %UNTITLED4 Summary of this function goes here
  %   Detailed explanation goes here
  % simulation for M-QAM transmission
  EbNodB = [0:2:40];
  EbNolin = 10.^(EbNodB/10) ;
  Pe_sim=[];
  
  % For M-QAM
  if(M==4)
  a=1;
  else
  a=4/log2(M);
  end
  b=3*log2(M)/(M-1);
  Pe=[];
  for i = 1:((40/2)+1),
      Pe= [Pe 0.5*a*(1-sqrt(0.5*b*EbNolin(i)/(1+0.5*b*EbNolin(i))))]; %THE APROXIMATION
  end                      % Ref: Wireless Communication, A. Goldsmith
  
  semilogy(EbNodB,Pe)
  xlabel('SNR, EbNo(dB)');
  ylabel('Bit error probability, Pe');
  title('Theoretical results of BER of M-QAM');
  legend(num2str(M));
  legend('-DynamicLegend')
  hold off
  
  end
  </code></pre>
  
  <p>That code works correctly but now i need to do a modification, the line indicated by aproximation has to be modified, instead of</p>
  
  <pre><code>    0.5*a*(1-sqrt(0.5*b*EbNolin(i)/(1+0.5*b*EbNolin(i))))
  </code></pre>
  
  <p>i need a new value that would be:</p>
  
  <pre><code>(a/pi)*int((a/pi)*mgf*(-b/(2*((sin(phi))^2)) integrated from phi = 0..pi/2
  </code></pre>
  
  <p>where</p>
  
  <pre><code>mgf = (2*(sin(phi))^2)/(2*(sin(phi))^2+b*EbNolin)
  </code></pre>
  
  <p>So I have modified my code as:</p>
  
  <pre><code>function y= m_qam_ray2(M)
  %UNTITLED4 Summary of this function goes here
  % Detailed explanation goes here
  % simulation for M-QAM transmission
  EbNodB = [0:2:40];
  EbNolin = 10.^(EbNodB/10) ;
  %Pe_sim=[];
  if(M==4)
      a=1; %Amplitud alpha_m
  else
      a=(4/log2(M))*(1-(1/sqr(M)));
  end
  
  b=3*log2(M)/(M-1); %beta_m
  
  %mgf= (2*(sin(phi))^2)/(2*(sin(phi))^2+b*EbNolin);
  
  Pe=[];
  
  for i = 1:((40/2)+1),
  
      Pe= [Pe (a/pi)*int((a/pi)*((2*((sin(phi))^2)/(2*((sin(phi))^2)+b*EbNolin(i)))*(-b/(2*((sin(phi))^2)), phi = 0..pi/2)];
  end                      % Ref: Wireless Communication, A. Goldsmith
  
  semilogy(EbNodB,Pe)
  xlabel('SNR, EbNo(dB)');
  ylabel('Bit error probability, Pe');
  title('Theoretical results of BER of M-QAM');
  legend(num2str(M));
  legend('-DynamicLegend')
  hold off
  </code></pre>
  
  <p>end</p>
  
  <p>In every loop of i I am doing the integral between 0 and pi/2 (i know it's not very eficient, but now i only need it to work), but i am getting errors constantly and dont know exactly why, the error line is the </p>
  
  <pre><code> Pe = [Pe (a/pi)*int(((2*((sin(phi))^2)/(2*((sin(phi))^2)+b*EbNolin(i)))*(-b/(2*((sin(phi))^2)))),  phi = 0..pi/2)];
  </code></pre>
  
  <p>the error is 
       ??? Error: File: m_qam_ray2.m Line: 22 Column: 108
       The expression to the left of the equals sign is not a valid target for an assignment.</p>
  
  <p>And i dont know if it is because my loop is bad programed or it is because of the integral.</p>
  
  <p>I would be very grateful if someone could help.</p>
  
  <p>Thanks :)</p>