title: How do I run the Initial value x0 also in parallel
body: <p>This code works fine but the plot is not correct because the optimization function <code>fmincon</code> will depend on the initial condition <code>x0</code> and the number of iterations. For each value of alpha (<code>a</code>) and beta (<code>b</code>), I should run the optimization many times with different initial conditions <code>x0</code> to verify that I am getting the right answer. More iterations might be required to get an accurate answer.</p>
  
  <p>I want to be able to run the optimization with different initial conditions for <code>x0</code>, <code>a</code> and <code>b</code>.</p>
  
  <p>Function file </p>
  
  <pre><code>function f = threestate2(x,a,b)
  c1 = cos(x(1))*(cos(x(5))*(cos(x(9))+cos(x(11)))+cos(x(7))*(cos(x(9))-cos(x(11))))...
     +cos(x(3))*(cos(x(5))*(cos(x(9))-cos(x(11)))-cos(x(7))*(cos(x(9))+cos(x(11))));
  c2=sin(x(1))*(sin(x(5))*(sin(x(9))*cos(x(2)+x(6)+x(10))+sin(x(11))*cos(x(2)+x(6)+x(12)))...
      +sin(x(7))*(sin(x(9))*cos(x(2)+x(8)+x(10))-sin(x(11))*cos(x(2)+x(8)+x(12))))...
      +sin(x(3))*(sin(x(5))*(sin(x(9))*cos(x(4)+x(6)+x(10))-sin(x(11))*cos(x(4)+x(6)+x(12)))...
      -sin(x(7))*(sin(x(9))*cos(x(4)+x(8)+x(10))+sin(x(11))*cos(x(4)+x(8)+x(12))));
  f=(a*a-b*b)*c1+2*a*b*c2;
  </code></pre>
  
  <p>Main file </p>
  
  <pre><code>%x=[x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10),x(11),x(12)]; % angles;
  
  lb=[0,0,0,0,0,0,0,0,0,0,0,0];
  ub=[pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi];
  x0=[pi/8;0;pi/3;0;0.7*pi;.6;0;pi/2;.5;0;pi/4;0];
  xout=[];
  fout=[];
  options = optimoptions(@fmincon,'Algorithm','interior-point','TolX',10^-10,'MaxIter',1500);
  a=0:0.01:1;
  w=NaN(length(a));
  
  for i=1:length(a)
       bhelp=(1-a(i)*a(i));
  if bhelp&gt;0
      b=sqrt(bhelp);
         [x,fval]=fmincon(@(x)threestate2(x,a(i),b),x0,[],[],[],[],lb,ub,[],options);
  w(i)=fval;
  w(i)=-w(i);
  B(i)=b;
  else
  w(i)=NaN;
  B(i)=b;
  end 
  end
  %surface(b,a,w)
  %view(3)
  %meshc(b,a,w)
  x=a.^2;
  plot(x,w)
  grid on
  ylabel('\fontname{Times New Roman} S_{max}(\Psi_{gs})')
  xlabel('\fontname{Times New Roman}\alpha^2')
  %ylabel('\fontname{Times New Roman}\beta')
  title('\fontname{Times New Roman} Maximum of the Svetlichny operator(\alpha|000&gt;+\beta|111&gt;)')
  </code></pre>