clear;
c = -.99:0.01:.99;
T = 0.01:0.01:1.99;
minValue = 10000;
minC = 0;
%S = (1 - c)/2 + T .* ( (c+1)/2 .* log( (c+1)/2 ) + ( 1 - c )/2 .* log( (1 - c)/2 ) );
for i = 1: length( c ),
    %temp =( ( c( i ) + 1 )/2 )* log( ( c( i ) + 1 ) / 2 ) + ( ( 1 - c( i ) ) / 2 ) * log( ( 1 - c( i ) ) / 2 );
    temp = ( (1 + c( i ) ) / 2 ) * log( (1 + c( i ) ) / 2  ) + ( ( 1 - c( i ) ) / 2 ) *  log( ( 1 - c( i ) ) / 2 );
    for l = 1: length( T ),
        S(l, i ) = 1 - 2 * c( i ) - (1 - 2 * c( i ))^2 + T(l )*temp/2;
    end;
end;
for i = 1:length( T ),
    minValue = 10000;
    for l = 1 : length( c ),
        if S( i , l ) <= minValue,
            minValue = S( i , l );
            minC = c( l );
            if S( i, l+1 ) > S( i , l ),
                break;
            end;
        end;
    end;
    minCS( i ) = minC;
    minCSV( i ) = minValue;
end;
plot3( T,  minCS , minValue, T ,  1 - minCS, minValue);