function [txt, s] = myApp(n, nslots)
% function [txt, s] = myApp(n, nslots)
% Purpose: demonstrates MATLAB PCT commands from function
% Computes s = 1 + 2 + 3 + . . + n with nslots cores

% Compute with the Parallel Computing Toolbox

s = 0;    % initialize sum of arithmetic sequence
parfor i=1:n
    s = s + i;       % s = 1 + 2 + 3 + . . + n
end

txt=sprintf(['Compute s = 1 + 2 + 3 + . . + n (n = %d)\n' ...
  'with Parallel Computing Toolbox parfor (%d cores)\n' ...
  'Computed s = %d; Expected s =  %d\n'], ... 
  n, nslots, s, n*(n+1)/2);

end   % end of function 

