clear;
c = 0.01:0.005:.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 = c( i ) * log( c( i ) ) + ( 1 - c( i ) ) *  log( 1 - c( i ) ); 
    for l = 1: length( T ),
        S(l, i ) = c( i ) - 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;
end;
plot( T,  minCS , T ,  1 - minCS);