%% nsection_spmd.m
%  
Nlabs=2;
interval=[-2*pi-.1 2*pi+.1];
f=@sin;
%%
parpool('local',Nlabs)
%%
n=100
spmd 
    Len=(interval(2)-interval(1))/Nlabs;
    a=interval(1)+(labindex-1)*Len;
    Labinterval=[a,a+Len]
    [br,c]=nsection(f,Labinterval,n);    
end
%%
[br{1} c{1}]
[br{2} c{2}]
%{
ans =
   -6.2852   -6.2192   -6.2522
   -3.1836   -3.1176   -3.1506
   -0.0160    0.0500    0.0170

ans =
   -0.0180    0.0480    0.0150
    3.0836    3.1496    3.1166
    6.2512    6.3172    6.2842
%}
%%
brack{1}=br{1}
brack{2}=br{2}
centers{1}=c{1}
centers{2}=c{2}
%%
delete(gcp)
%%
brackets=[brack{1};brack{2}]
cent=[centers{1};centers{2}]
%% Visualization
close all
x=linspace(interval(1),interval(2));y=sin(x);
plot(x,y);grid on;shg
hold on
lefts=brackets(:,1);
rights=brackets(:,2);
plot(lefts,-0.1,'rx')
plot(rights,0.1,'bo')
plot(cent,0*cent,'k*')
%stem(lefts,-0.1*ones(size(lefts)))
% legend('f','left','right','midpoins')
%stem(rights,0.1*ones(size(rights)))
%stem(cent,.2*ones(size(cent)))
tol=0.1;
title(['n= ' num2str(n) ', tol = ' num2str(tol)])


