% sliding friction problem
function sliding_function

set(0,                           ...
   'defaultaxesfontsize', 20,   ...
   'defaultaxeslinewidth', 1.2, ...
   'defaultlinelinewidth', 2.0, ...
   'defaultpatchlinewidth', 0.7); 

global   V

cmykflg=0;
%if cmykflg=1, this code will make cmyk figure files
%cmykflg = 1;

%parameters
csi = 0.0005; % drag coefficient

blist = [0.5,1,2];  % list of b/a values
for jb = 1:3
beta = blist(jb);

V = 0.001;
for j = 1:300
    dv = (j-1)*0.01;  % list of values of v
    V = V + dv;
    v(j) = V;
tstep = 0.1;
t_end = 10;  % need to take this large enough that equations go to their steady values

%specify the output points
tspan = [0:tstep:t_end];

s0 = [1;0;0];
%solve the three differential equations
[T,S] = ode23s(@deRHS,tspan, s0 );  
n = S(:,1);
N = S(:,2);
F = S(:,3);
 
n0 = 1/(beta*V+N(end));
N0(j) = n0;

force =  n0*F(end);
Fc(j) = force;
%figure(1)
%plot(T,n)
%hold on
end
figure(2)
plot(v,Fc,'linewidth',2)
xlabel('v','fontsize',20)
ylabel('\kappa F/(kN_T)','fontsize',20)
 hold on
 
 figure(1)
 plot(v+Fc/csi,v,'linewidth',2)
 hold on
 
end
figure(2)
axis([0 200 0 0.4])
text(20,0.045,'K_d=2.0','fontsize',20)
text(60,0.125,'K_d=1.0','fontsize',20)
text(80,0.195,'K_d=0.5','fontsize',20)
if(cmykflg==1)
  print('../../figs_c/chapt_9/slider_F_vs_v','-deps','-cmyk')
end 
 
figure(1)
text(50,52,'K_d=2.0','fontsize',20)
text(306,52,'K_d=1.0','fontsize',20)
text(450,200 ,'K_d=0.5','fontsize',20)
xlabel('v_f','fontsize',20)
ylabel('v','fontsize',20)
if(cmykflg==1)
  print('../../figs_c/chapt_9/V_vs_Vf_slider','-deps','-cmyk')
 end 
end
%the right hand side for ode simulation:
function s_prime=deRHS(x,s)
global   V
 n = s(1);
 N = s(2);
 F = s(3);
Fn =  - exp(x)*n/V;
FN = n;
FF = x*n;
 
s_prime = [Fn FN FF]';

end
