%% Howework 3.2

KT=4.1*10^-21;  %J
nw=10^-3;       %Pa s
h=5*10^-9;      %m
a=10^-9;        %m
D1=10^-12;      %m^2/s
gamma=.577;

%Many ways to solve the transcendental equation numerically. 
%Matlab can do this for you using 'fzero'

options=optimset;
fun=inline('D-KT/(4*pi*nm*h)*(log( (h*nm)/(a*nw) )-gamma)','nm','D','h','a','nw','KT','gamma');
X0=.3;  %lipid bilayers have viscosity ~ 0.3 Pa s;
X = fzero(fun,.5,options,D1,h,a,nw,KT,gamma)
nm=X
fun(nm,D1,h,a,nw,KT,gamma)
 
 
%check
D=KT/(4*pi*nm*h)*(log( (h*nm)/(a*nw) )-gamma)
N=(1:100);

%check Lsd
Lsd=h*nm/2/nw
a/Lsd   %should be much less than 1


D_N=KT/(4*pi*nm*h)*(log( (h*nm)./(a*sqrt(N)*nw))-gamma);

figure
plot(N,D_N*10^12,'linewidth',2)
xlabel('Number of proteins in cluster')
ylabel('Diffusion constant (\mum^2/s)')


    