About this blog

I feel this blog as a reflection of my thoughts to myself , and sometimes as a public diary, and the is my only friend to share my thoughts who says never a "oh no! ,you shouldn't....That is boring...."

Types of Calculus

1. Leibniz Calculus, derivatives-functions
2. Newton's Calculus , Fluxions-Fluents
3. Lambda Calculus, Computer science
4. Ito Calculus, Random Processes-Finance models
5. Variational Calculus, first variation-functionals
6. Propositional Calculus, Logic

Humans are horrible criminals.

Our humanity stands nowadays at seedless fruits and boneless chicken.

Octave Matlab code Two friends wanted to meet for 1 hour. at least ,over a time-window of N hours

The method of solving is brute-force and the codes involved were optimized at my best.

All possible configurations of hours(n) spent over (N hours window) by each friend is given by either combR or comb.
Octave code for the subroutine : combR.m (depends on nested looping ann optimization)
  Octave code for the subroutine : comb.m (So many for loops and functions were used finally the result will same as combR)
Surprisingly, both the methods were taking nearly equal time for smaller N values.
   The final solution can be sought from friendsMeet(N) programme.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Codes start here------>>>>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$$$$$$$$$$$$$
combR.m code: 
$$$$$$$$$$$$$
function X=combR(N,n,Xpre)
if n>N
  return ;
endif
if (n==1)
    X=eye(N);
else
    if nargin==3
     X=Xpre;
    else
     X=combR(N,n-1);
    endif
    Y=[ ];
    for col=1:size(X,2)
      [rowidx]=find(X(:,col)==0);
      for g=1:length(rowidx)
        Y=[Y X(:,col)];
        Y(rowidx(g),end)=1;
      endfor
    endfor
    X=unique(Y',"rows")';
endif
endfunction

$$$$$$$$$$$$$
comb.m   code: 
$$$$$$$$$$$$$
function [X]=comb(N, n)
%% Generates all possible combinations for N  choose n
if n>N
  return ;
endif
X=eye(N);
for B=1:n
  for i=1:size(X,2)
    for j=1:N
      if(X(j,i)==1)
        continue
      endif
      X=[X, X(:,i)];
      X(j,end)=1;
    endfor
  endfor
  [idx]=find(sum(X,1)==B);
  X=X(:,idx);
  X=unique(X',"rows")';
endfor
endfunction

$$$$$$$$$$$$$
main function friendsMeet.m   code: 
$$$$$$$$$$$$$
function H=friendsMeet(N)
%% Find number of hours each, two friends should wait
%% at a location so that they can meet for at least
%% for one hour
%% Input: (N) Available time window for both.
%% Each friend spends time of integer
%% hours starting from an integer clock hour.

%% The technique is Brute force or Trail-n-Error
if nargin==0
  N=8;
endif
M=X=[];

for i=1:N
 if i==1
   Y=combR(N,i);
 else
   Y=combR(N,i,Y);
 endif
 X=[X, Y];
endfor

## j=0;
## for a=1:size(X,2)
##   for b=1:size(X,2)
##     M(++j)=X(:,a)'*X(:,b);
##     Hc(j)=min(sum(X(:,a)),sum(X(:,b)));
##   endfor
## endfor
 M=(X'*X)(:);
 Hc=full(sum(X));
 Hc=min(Hc,Hc')(:); %%Symmetric matrix output
 %hist(Hc(M>0))
 H=mean(Hc(M>0));
 V=std(Hc(M>0),1);
 printf("For %f%% chances Spend atleast %d hours\n", 99.7, H+3*V);
 printf("For %f%% chances Spend atleast %d hours\n", 95, H+2*V);
 printf("For %f%% chances Spend atleast %d hours\n", 68, H+V);
endfunction



N choose n Matlab Octave program

The following is an Octave/ Matlab program to generate all N chose n choices for given N and n.

function [X]=comb(N, n)
%% Generates all possible combinations for N  choose n
X=[];
  for i=1:N
    X=[X,eye(N)(:,i)];
  endfor
for B=1:n
  for i=1:size(X,2)
    for j=1:N
      if(X(j,i)==1)
        continue
      endif
      X=[X, X(:,i)];
      X(j,end)=1;
    endfor
  endfor
  [idx]=find(sum(X,1)==B);
  X=X(:,idx);
  X=unique(X',"rows")';
endfor
size(X,2)
 endfunction

The most expensive graph of 19th century is India's census on growth rate of population.

Something suspicious just before independence. I mean data being tampered by the Brits aftet the great Bengal famine or by fallacious census by us after the independence.!
Whom do you refute in these two choices??