% batch ex 1
clear;

jb= batch('batch_quadint')  % launch a task without a cluster
wait(jb);                   % wait till completion
load(jb);                   % load the workspace from the worker 

disp(v)

%
% batch ex 2
clear;

f = @(x) (sqrt(16 - x .^2)/8);
clst = parcluster('local');

nj = 50;                   % will use 50 approximations of PI
p  = zeros(1, nj);         % will contain these approximations
jb = cell(nj);         

for k=1:nj
    % evaluate the function quadint returning 1 parameter and taking
    % arguments f, -4, 4, 1000*k, on the cluster clst.
    jb{k} = batch(clst, @quadint, 1, {f, -4, 4, 1000*k}); % save the job ID in jb(k)
end

% now wait for completion
for k=1:nj
    wait(jb{k});
    r = fetchOutputs(jb{k});
    p(k) = r{1};           % a single output from quadint(...)
    delete(jb{k});
end

% plot the approximation:
plot(pi-p)
