title: Parallel pooling on MATLAB for Bifurcation
body: <p>I'm new to this concept of parallel pooling on MATLAB (I'm using the version 2019 a) and coding. This code that I'm going to share with you was available on the net, with some few modifications that I've made it for my requirements. </p>
  
  <p>Problem Statement: I'm having a non-linear system (Rossler equation) &amp; I have to plot its Bifurcation diagram, I tried to do it normally using for loop but its computation time was too much and my computer got hanged several times, so I got an advice to parallel pool my code in order to come out of this problem. I tried to learn how to parallel pool using MATLAB on the net but still I'm not able to resolve my Issues as there are still some problems since there are 2 parfor loops in my code I'm having problems with Indexing and in assignment of the global parameter (Please note: This code is written for normal execution without using parallel pooling).</p>
  
  <p>I'm attaching my code below here, please excuse if I've mentioned a lot many lines of codes. </p>
  
  <pre><code>clc;
  a = 0.2; b = 0.2; global c;
  crange = 1:0.05:90; % Range for parameter c
  k = 0; tspan = 0:0.1:500; % Time interval for solving Rossler system
  xmax = []; % A matrix for storing the sorted value of x1
  
  for c = crange
  f = @(t,x) [-x(2)-x(3); x(1)+a*x(2); b+x(3)*(x(1)-c)];
      x0 = [1 1 0]; % initial condition for Rossler system 
      k = k + 1;
      [t,x] = ode45(f,tspan,x0); % call ode() to solve Rossler system
      count = find(t&gt;100); % find all the t values which is &gt;10  
      x = x(count,:);
      j = 1; 
      n = length(x(:,1)); % find the length of vector x1(x in our problem)
  
      for i=2 : n-1
         % check for the min value in 1st column of sol matrix
         if (x(i-1,1)+eps) &lt; x(i,1) &amp;&amp; x(i,1) &gt; (x(i+1,1)+eps)  
             xmax(k,j)=x(i,1); % Sorting the values of x1 in increasing order
             j=j+1;
         end 
      end
  
      % generating bifurcation map by plotting j-1 element of kth row each time
      if j&gt;1
          plot(c,xmax(k,1:j-1),'k.','MarkerSize',1);
      end 
  
      hold on;
      index(k)=j-1;    
  end
  xlabel('Bifuracation parameter c');
  ylabel('x max');
  title('Bifurcation diagram for c'); 
  </code></pre>